[英]R xtable: LaTex Commands output to HTML
I'm trying to use a LaTeX command to apply special formatting(shaded row) to one row of a table, and then to output it all directly to HTML. 我正在尝试使用LaTeX命令将特殊格式(阴影行)应用于表的一行,然后将其全部直接输出到HTML。 I seem to be stuck in an "either/or" situation - either the LaTeX command is included and I get LaTeX output, or the command is omitted and I get HTML.
我似乎陷入了“非此即彼”的局面-包含LaTeX命令并获得LaTeX输出,或者省略该命令并获得HTML。 I want to press the "Knit" button and get a formatted report, with the shaded row included.
我想按下“编织”按钮,并获得带有阴影行的格式化报告。
What's the flow from R code to LaTeX to HTML output, with one press of a button? 一按一个按钮,从R代码到LaTeX再到HTML输出的流程是什么?
---
title: "Bug List"
output:
html_document
---
{r echo=FALSE, results='asis'}
library(knitr,quietly = TRUE,verbose = FALSE)
library(xtable,quietly = TRUE,verbose = FALSE)
data<-data.frame(matrix(as.character(rnorm(80,50,2)),ncol=8))
names(data)<-c("BugActivity","Key","Summary","Priority","ExternalStatus","WaitingFor","InternalStatus","InternalBug")
shadeCommand <- rep("\\rowcolor[red]{0.90}", 1)
print(xtable(data), type="html",include.rownames= FALSE, floating=FALSE,
add.to.row=list(pos=list(4),command=c("\\rowcolor[gray]{.8} ")))
```
Environment: R Studio on Windows 环境:Windows上的R Studio
Thanks very much! 非常感谢!
I obviously have my biases...but pixiedust
* allows you to create your tables in either latex or html using the same set of commands (although the latex output is a slightly more limited than the html). 我显然有偏见...但是
pixiedust
*允许您使用相同的命令集在乳胶或html中创建表(尽管乳胶的输出比html稍微受限)。
---
title: "Bug List"
output:
html_document: null
pdf_document: null
header-includes:
- \usepackage[dvipsnames,table]{xcolor}
- \usepackage{longtable}
- \usepackage{arydshln}
- \usepackage{amssymb}
- \usepackage{graphicx}
- \usepackage{multirow}
---
```{r, echo=FALSE}
library(pixiedust)
set.seed(55)
data<-data.frame(matrix(as.character(rnorm(80,50,2)),ncol=8))
names(data)<-c("BugActivity","Key","Summary","Priority",
"ExternalStatus","WaitingFor","InternalStatus","InternalBug")
dust(data) %>%
sprinkle(rows = 5,
bg = "#D0D0D0") %>%
medley_bw() %>%
sprinkle_print_method("html")
```
If you want to change the output to latex, you just change the last line to sprinkle_print_method("latex")
如果要将输出更改为乳胶,只需将最后一行更改为
sprinkle_print_method("latex")
*
Use the dev version right now devtools::install_github("nutterb/pixiedust")
. *
使用dev版本devtools::install_github("nutterb/pixiedust")
。 That version should go up to CRAN sometime in late January. 该版本应在1月下旬的某个时候发布到CRAN。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.