Undroid
Undroid

Reputation: 175

Is it possible to rmarkdown::render a pdf_document for kable tables with styling?

I'm trying to render a Rmd file in a script:

rmarkdown::render("Test.Rmd")

Which works fine when I knit the file itself but if it contains kable_styling options at all e.g.

```{r, echo = FALSE}
library(kableExtra)
dt <- mtcars[1:5, 1:6]
kable(dt, align = "c", format="latex", booktabs=T) %>% 
  kable_styling(latex_options=c("striped", "scale_down"), font_size = 7, html_font = "Times New Roman")
#three backticks to close

I get this error:

! LaTeX Error: Unknown float option `H'.

I've tried each argument by itself, but it only runs if I remove the whole line.

Is there a way around this? I want to use render so I can dynamically generate the filename - maybe there is a better way?

Upvotes: 3

Views: 1189

Answers (1)

Undroid
Undroid

Reputation: 175

Thanks to Stacker. The solution is to load the required packages in the YAML:

header-includes:
  \usepackage{float}
  \usepackage{booktabs}
  \usepackage{colortbl}

The error changes each time.

Upvotes: 10

Related Questions