我在 CentOS 服务器上通过 R/Sweave/tinytex 生成 PDF 的过程中遇到了问题。这是运行该过程的命令:
(generateReport.R)
Sweave(rnwFile, encoding = "UTF-8", output=filename)
tools::texi2pdf(filename)
一旦通过 tools:texi2pdf 命令将 .tex 转换为 .pdf 就会发生错误,内容如下:
! Missing \endcsname inserted.
<to be read again>
\egroup
l.118 \begin
{threeparttable}
! ==> Fatal error occurred, no output PDF file produced!
Calls: <Anonymous> -> texi2dvi
在切碎我的代码以找出错误发生的位置后,我可以判断它源自其 huxtable 中。我将在此处发布 RNW 文件的重要部分:
\documentclass[letterpaper,12pt]{book}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{hyperref}
\usepackage{array}
\usepackage{lastpage}
\usepackage{multirow}
\usepackage{fancyhdr}
\usepackage{longtable}
\usepackage{array}
\usepackage{caption}
\usepackage{siunitx}
\usepackage[normalem]{ulem}
\usepackage{colortbl}
\usepackage{hhline}
\usepackage{calc}
\usepackage{tabularx}
\usepackage{threeparttable}
\usepackage{wrapfig}
\usepackage{adjustbox}
\usepackage[hmargin=1cm,top=5cm,headheight=6cm,footskip=40pt]{geometry}
<<external-code, warning=FALSE, message=FALSE, echo=FALSE>>=
options(width=60)
library(dplyr)
library(stringr)
library(mongolite)
library(huxtable)
library(knitr)
# r code for getting data here, works fine
#....................
huxTable <- as_hux(df1)
huxTable <- huxTable %>%
set_align(1, everywhere, "center") %>%
set_all_borders(brdr(0.5, "solid", "black")) %>%
set_align(-1, 1, ".") %>%
#set_colspan(1, 2, 5) %>%
set_font_size(everywhere, everywhere, 8)
@
\pagestyle{fancy}
\renewcommand{\headrulewidth}{0pt}
\fancyhead[C]{%
#the header is full of other fields/data, but I have confirmed it is unrelated to this issue.
}
\begin{document}
\SweaveOpts{concordance=TRUE}
<<results=tex, include=TRUE, warning=FALSE, message=FALSE, echo=FALSE>>=
print_latex(huxTable)
@
\end{document}
我已经确认 huxtable 中的文本没有任何导致它出错的特殊字符。我还确保了失败尝试生成的 .aux 和 .out 文件也被删除。我已经生成了其他具有类似依赖关系的 PDF,所以我对这里发生的事情感到困惑。有任何想法吗?