如何将kableExtra与乳胶页脚结合起来?

时间:2018-01-19 23:46:30

标签: r knitr r-markdown kable kableextra

我正在尝试将以下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 {document}

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

1 个答案:

答案 0 :(得分:1)

在加载此软件包并自行输入必要的LaTeX软件包之前,可以通过将全局选项kableExtra设置为kableExtra.latex.load_packages来告诉FALSE不加载任何LaTeX软件包。

您可以参考包vignetteGetting 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 = '-')
```