Booktabs 和 xtable 因使用 RStudio 的 Rmarkdown 而失败。 Tufte 模板工作正常,但使用标准 .Rmd
文件失败并显示错误消息:
! Undefined control sequence.
l.133 \toprule
pandoc.exe: Error producing PDF from TeX source
Error: pandoc document conversion failed with error 43
一个可重现的例子:
---
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 版本 3.1.2 (2014-10-31)
平台:x86_64-w64-mingw32/x64(64位)
已安装最新版本的 Pandoc。
最佳答案
尝试包含一个文件 header.tex
其中您依赖于 booktabs 包。见 the latex options rmarkdown 了解详情。
编辑:虽然包含标题很方便并且允许进行更广泛的更改,但我们在这里使用顶级选项 tables: true
.所以上面例子的最小变化是
---
title: "Testing booktabs"
author: "r.bot"
date: "June 11, 2015"
output: pdf_document
tables: true
---
之后 sample
xtable
输出与 booktabs 一起出现。
关于r - 在 Rmarkdown 中使用 booktabs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30780998/