Here is a file kable.Rmd that knits properly in RStudio:
---
title: "latex kable"
output: pdf_document
---
```{r table1, echo=FALSE}
library(magrittr)
library(kableExtra)
kable(data.frame(a=c(1,2,3), b=c(4,5,6))) %>%
kable_styling(latex_options = c("striped", "hold_position", "repeat_header"),
full_width = F)
```
The output shows a table:
Here is a YAML file to configure bookdown called kable_bookdown.yml:
# See https://bookdown.org/yihui/bookdown/usage.html
rmd_files: ["kable.Rmd"]
delete_merged_file: true
Here is a call to render:
bookdown::render_book(input='kable.Rmd', config_file='kable_bookdown.yml')
Here is the error I get from that render:
/Applications/RStudio.app/Contents/MacOS/pandoc/pandoc +RTS -K512m -RTS _main.utf8.md --to latex --from markdown+autolink_bare_uris+tex_math_single_backslash --output _main.tex --self-contained --highlight-style tango --pdf-engine pdflatex --variable graphics --lua-filter /Library/Frameworks/R.framework/Versions/3.6/Resources/library/rmarkdown/rmd/lua/pagebreak.lua --lua-filter /Library/Frameworks/R.framework/Versions/3.6/Resources/library/rmarkdown/rmd/lua/latex-div.lua --variable 'geometry:margin=1in'
! Undefined control sequence.
<recently read> \rowcolor
The rowcolor likely comes from the "striped" latex option.
Why does it work in RStudio, but not through the render call?
RStudio seems to be using the same latex (pdflatex).
I'm using RStudio Version 1.2.5042, R 3.6.3, bookdown 0.18, kableExtra 1.1.0, knitr 1.28, tinytex 0.20.
EDIT: I was not able to get header_includes to work. Adding this to kable.Rmd worked for me:
header-includes:
- \usepackage{colortbl}
- \usepackage{xcolor}
EDIT 2: This also worked for me (from here):
output:
pdf_document:
# list latex packages:
extra_dependencies: ["colortbl", "xcolor"]
