我正在尝试将rmarkdown文件编织为包含 kableExtra 功能的PDF文件,例如:
但是我总是遇到以下错误:
! Extra alignment tab has been changed to \cr.
<template> \endtemplate
l.184 \end{tabular}}
pandoc.exe: Error producing PDF
Error: pandoc document conversion failed with error 43
Ejecución interrumpida
我正在执行的一个简单示例是:
```
---
output:
pdf_document:
keep_tex: yes
classoption: table
header-includes:
- \usepackage{array}
- \usepackage{float}
- \usepackage{xcolor}
---
```{r results='asis'}
options(kableExtra.latex.load_packages = FALSE)
require(kableExtra)
print(kable(head(cars),"latex")%>%kable_styling(latex_options = c("striped",
"bordered"))
%>%column_spec(column=1:2,width = "0.5in") %>%
kable_styling(c("striped", "bordered"),latex_options =
"scale_down")%>% add_header_above(c(" "=7,
"Absolute"=1,"Relative"=1,"Absolute"=1,"Relative"=1,
"Absolute"=1,"Relative"=1,"Absolute"=1,"Relative"=1,"Absolute"=1,
"Relative"=1))%>%
add_header_above(c(" "= 1,"Non-weighted"=1,"Weighted"=1,"Non-
weighted"=1,"Weighted"=1,"Non-weighted"=1,
"Weighted"=1,"Weighted"=2,"Non-weighted"=2,"Weighted"=2,"Non-
weighted"=2,"Weighted"=2))%>%
add_header_above(c("Theoretical Values"= 1,"First-Order Predicted
Value"=2,"Second-Order Predicted Value"=2,
"Third-Order Predicted Value"=2,
"Non-linearity 1st Order"=2,"Non-linearity 2nd Order"=4,"Non-linearity 3rd
Order"=4)))
```
有人可以帮助我解决这个问题吗?
任何线索我都会感谢!
答案 0 :(得分:1)
您要告诉kableExtra
不要加载LaTeX软件包(为什么?),因此您必须自己执行此操作。您使用的功能需要array
,float
和xcolor
以及table
选项。一个困难是fancyvrb
v3.0已经用other options加载了xcolor
。您可以通过提供table
作为类选项来避免这种情况:
---
output:
pdf_document:
keep_tex: yes
classoption: table
header-includes:
- \usepackage{array}
- \usepackage{float}
---
```{r results='asis'}
options(kableExtra.latex.load_packages = FALSE)
require(kableExtra)
print(kable(head(cars),"latex") %>%column_spec(column=1:2,width = "0.5in"))
```
```{r results='asis'}
print(kable(head(cars),"latex")%>%kable_styling(latex_options = c("striped", "bordered")))
```