I would like to produce "LaTeX-like" table within an HTM document using knitr
markdown (.Rmd
) through:
我想使用knitr markdown (.Rmd)在HTM文档中生成“类latex”表:
knitr::knit2html(input="D:/...Rmd", output="D:/...report.html")
Here is an example. However, if I decided to produce a report, the LaTeX table would be incorrect:
这是一个例子。但是,如果我决定写一份报告,那么乳胶表将是不正确的:
library(xtable)
xtabl <- xtable(head(CO2))
print(xtabl, type="latex", include.rownames=FALSE)
The above gives:
上面给:
As suggested here is the result. It was NOT a "LaTeX-like" table!
结果如下所示。这不是一张“先知”式的桌子!
xtabl <- xtable(head(CO2))
print.xtable(xtabl, type="html", include.rownames=FALSE)
EDIT:
编辑:
What I mean by "LaTeX-like" table is this:
我所说的“先知”表是这样的:
3 个解决方案
#1
1
Here's an example of a basic table with htmlTable
:
下面是一个使用htmlTable的基本表示例:
---
title: "Untitled"
author: "Author"
date: "2/5/2017"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```
```{r}
library(htmlTable)
```
```{r, results="asis"}
tab = cbind.data.frame(
sapply(iris[1:5 , sapply(iris, is.numeric)], function(x) sprintf("%1.1f", x)),
Species=iris$Species[1:5]
)
htmlTable(tab, rnames=FALSE, align="rrrrr", align.header="rrrrr",
css.cell = c(rep("padding-left: 5em", 4), "padding-left: 2em"))
```
#2
1
The R Markdown cheat sheet provides a visual comparison of libraries kable, xtable and stargazer. Stargazer could be what you are looking for.
rmarkdown备考表提供了一个可视化的比较库可以使用,xtable和stargazer。你在寻找的可能就是星空。
Also have a look into the htmlTable package.
还可以查看htmlTable包。
Further customizations could be made with a custom CSS file.
可以使用自定义CSS文件进行进一步的定制。
#3
0
I have used knitr::kable
for producing the desired tables.
我已经使用knitr:::用于生产所需的表。
mydata <- data.frame(SrNo=c(1,2,3,4), websites=c("*", "twitter", "facebook", "google"))
knitr::kable(mydata)
kable
function accepts a format
argument with possible values latex
, html
, etc. see the documentation for details
函数接受带有可能值latex、html等的格式参数,详细信息请参阅文档
Complete Markdown file
完整的减价文件
---
title: "kable"
author: "Imran Ali"
date: "February 6, 2017"
output: pdf_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r, echo=FALSE}
mydata <- data.frame(SrNo=c(1,2,3,4), websites=c("*", "twitter", "facebook", "google"))
knitr::kable(mydata)
```
#1
1
Here's an example of a basic table with htmlTable
:
下面是一个使用htmlTable的基本表示例:
---
title: "Untitled"
author: "Author"
date: "2/5/2017"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```
```{r}
library(htmlTable)
```
```{r, results="asis"}
tab = cbind.data.frame(
sapply(iris[1:5 , sapply(iris, is.numeric)], function(x) sprintf("%1.1f", x)),
Species=iris$Species[1:5]
)
htmlTable(tab, rnames=FALSE, align="rrrrr", align.header="rrrrr",
css.cell = c(rep("padding-left: 5em", 4), "padding-left: 2em"))
```
#2
1
The R Markdown cheat sheet provides a visual comparison of libraries kable, xtable and stargazer. Stargazer could be what you are looking for.
rmarkdown备考表提供了一个可视化的比较库可以使用,xtable和stargazer。你在寻找的可能就是星空。
Also have a look into the htmlTable package.
还可以查看htmlTable包。
Further customizations could be made with a custom CSS file.
可以使用自定义CSS文件进行进一步的定制。
#3
0
I have used knitr::kable
for producing the desired tables.
我已经使用knitr:::用于生产所需的表。
mydata <- data.frame(SrNo=c(1,2,3,4), websites=c("*", "twitter", "facebook", "google"))
knitr::kable(mydata)
kable
function accepts a format
argument with possible values latex
, html
, etc. see the documentation for details
函数接受带有可能值latex、html等的格式参数,详细信息请参阅文档
Complete Markdown file
完整的减价文件
---
title: "kable"
author: "Imran Ali"
date: "February 6, 2017"
output: pdf_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r, echo=FALSE}
mydata <- data.frame(SrNo=c(1,2,3,4), websites=c("*", "twitter", "facebook", "google"))
knitr::kable(mydata)
```