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. 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. 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?
---
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
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).
---
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")
*
Use the dev version right now devtools::install_github("nutterb/pixiedust")
. That version should go up to CRAN sometime in late January.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.