1

我正在尝试将以下 RMarkdown 编织为 pdf:

---
title: 'Title'
params:
  set_title: 'title report'
header-includes:
- \usepackage{fancyhdr}
- \pagestyle{fancy}
- \lhead{}
- \chead{}
- \rhead{Semester Graduation Report `r params$set_title`}
output:
  pdf_document:
    latex_engine: xelatex
---

```{r, include =FALSE}
knitr::opts_chunk$set(echo = F, message = F, warning = F)
library(knitr)
library(tidyverse)
library(kableExtra)
options(knitr.kable.NA = '-')
```


```{r, results='asis'}
kable(mtcars, format = 'latex', longtable = T, booktabs = T, caption='This is a caption' ) %>% 
  add_header_above(c(" " = 1, "something"=2, "something else"=2)) %>% 
  kable_styling(latex_options = c("repeat_header"))
```

```{r}
kable(mtcars)
```

但是,它检索和错误

!缺少插入的 $。$ l.239 \end{文档}

我注意到如果我删除header-includes它可以正常工作,但我宁愿不必删除标题。我究竟做错了什么?

4

1 回答 1

1

您可以通过将全局选项设置为在加载此包之前告诉kableExtra不要加载任何 LaTeX 包并自行放入必要的 LaTeX 包。kableExtra.latex.load_packagesFALSE

你可以参考包小插曲Getting Started的章节。(请原谅我在图解代码中的错字...)

在这种情况下,你做

---
title: 'Title'
params:
  set_title: 'title report'
header-includes:
- \usepackage{fancyhdr}
- \pagestyle{fancy}
- \lhead{}
- \chead{}
- \rhead{Semester Graduation Report `r params$set_title`}
- \usepackage{booktabs}
- \usepackage{longtable}
- \usepackage{array}
- \usepackage{multirow}
- \usepackage[table]{xcolor}
- \usepackage{wrapfig}
- \usepackage{float}
- \usepackage{colortbl}
- \usepackage{pdflscape}
- \usepackage{tabu}
- \usepackage{threeparttable}
- \usepackage[normalem]{ulem}
output:
  pdf_document:
    latex_engine: xelatex
---

```{r, include =FALSE}
knitr::opts_chunk$set(echo = F, message = F, warning = F)
library(knitr)
library(tidyverse)
options(kableExtra.latex.load_packages = FALSE)
library(kableExtra)
options(knitr.kable.NA = '-')
```
于 2018-01-20T04:16:37.287 回答