Using booktabs with Rmarkdown

4.4k views Asked by At

Booktabs and xtable fail with Rmarkdown using RStudio. The Tufte template works fine, but using a standard .Rmd file fails with the error message:

! Undefined control sequence.
l.133   \toprule

pandoc.exe: Error producing PDF from TeX source
Error: pandoc document conversion failed with error 43

A reproducible example:

---
title: "Testing booktabs"
author: "r.bot"
date: "11 June 2015"
output: pdf_document
---

```{r, results='asis'}
library(xtable)
options(xtable.comment = FALSE)
options(xtable.booktabs = TRUE)
xtable(head(mtcars[,1:6]), caption = "First rows of mtcars")
```

R version 3.1.2 (2014-10-31) Platform: x86_64-w64-mingw32/x64 (64-bit) Latest version of Pandoc installed.

1

There are 1 answers

7
Dirk is no longer here On BEST ANSWER

Try including a file header.tex in which you depend on the booktabs package. See the latex options for rmarkdown for details.

Edit: While the inclusion of headers is convenient and allows for wider ranging changes, here we get by with the top-level options tables: true. So the minimal change for the example above is

---
title: "Testing booktabs"
author: "r.bot"
date: "June 11, 2015"
output: pdf_document
tables: true
---

after which the sample xtable output appears with booktabs.