简体   繁体   English

是否可以 rmarkdown::render a pdf_document 用于带有样式的 kable 表?

[英]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:我正在尝试在脚本中呈现 Rmd 文件:

rmarkdown::render("Test.Rmd")

Which works fine when I knit the file itself but if it contains kable_styling options at all eg当我编织文件本身时效果很好,但如果它完全包含 kable_styling 选项,例如

```{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?我想使用渲染,所以我可以动态生成文件名 - 也许有更好的方法?

Thanks to Stacker .感谢堆垛机 The solution is to load the required packages in the YAML:解决方法是在YAML中加载需要的包:

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

The error changes each time.错误每次都会改变。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM