When I use kableExtra for a PDF output, the table renders beautifully, BUT gives an error if there isn't another, non-kable extra table in the program. Has anyone else seen this behavior? the file appears to knit fine, but then throws an error in pandoc?
For example, this code:
---
output:
beamer_presentation:
fontsize: 10pt
---
```{r global_options, include=FALSE}
library(rmarkdown)
library(knitr)
library(kableExtra)
```
### Slide with table
```{r echo=FALSE, warning=FALSE, message=FALSE}
df=mtcars[1:8,1:3]
kable(df,format="latex",booktabs=T,row.names=F) %>%
row_spec(6, color = "red")
```
Gives this error
processing file: t.rmd
List of 1
$ include: logi FALSE
|....................................... | 60%
ordinary text without R code
|.................................................... | 80%
label: unnamed-chunk-1 (with options)
List of 3
$ echo : logi FALSE
$ warning: logi FALSE
$ message: logi FALSE
|.................................................................| 100%
ordinary text without R code
"C:/PROGRA~2/Pandoc/pandoc" +RTS -K512m -RTS t.utf8.md --to beamer --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output t.pdf --highlight-style tango --latex-engine pdflatex
output file: t.knit.md
! Undefined control sequence.
\beamer@doifinframe ...in {tabular}{rrr} \toprule
mpg & cyl & disp\\ \midrul...
l.86 \end{frame}
pandoc.exe: Error producing PDF
Error: pandoc document conversion failed with error 43
In addition: Warning message:
running command '"C:/PROGRA~2/Pandoc/pandoc" +RTS -K512m -RTS t.utf8.md --to beamer --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output t.pdf --highlight-style tango --latex-engine pdflatex' had status 43
Execution halted
But if I add one more slide with a dummy table, it prints beautifully:
---
output:
beamer_presentation:
fontsize: 10pt
---
```{r global_options, include=FALSE}
library(rmarkdown)
library(knitr)
library(kableExtra)
```
### Slide with table
```{r echo=FALSE, warning=FALSE, message=FALSE}
df=mtcars[1:8,1:3]
kable(df,format="latex",booktabs=T,row.names=F) %>%
row_spec(6, color = "red")
```
### Non-kableExtra table needed for some reason?
```{r echo=FALSE}
kable(df)
```
Has anyone else seen this behavior? Any workarounds besides "put a dummy table as the last slide?"
Beamer slides does not allow
kableExtra
to load latex packages automatically as it does in regular pdf document. You saw that error message from LaTeX because booktabs was not loaded. When you put an normal markdown table, some magic in rmarkdown pandoc template will loadbooktabs
&longtable
automatically, that's why the error was gone.You can follow the documentation in the
Getting Started
section of thekableExtra
documentation and putNote that I removed
- \usepackage[table]{xcolor}
from the list because beamer loadedxcolor
with a different option settings.