以下代码在 knitr 运行后导致 LaTeX 出现“参数失控”错误:
\documentclass{article}
\begin{document}
<<fig.cap="This causes \\texttt{problems.}">>=
plot(1:10,10:1)
@
\end{document}
原因尚不清楚,所以我希望这对可能遇到此问题的其他人有所帮助。
最佳答案
出现问题是因为,如"Power of Graphics in knitr"所述
The default short caption is extracted from the caption by truncating it at the first period or colon or semi-colon.
因此,通过编织上面的示例生成的.tex 文件包含以下内容
\caption[This causes \texttt{problems]{This causes \texttt{problems.}
解决方案是提供一个不会被过早截断的简短说明,例如,
\documentclass{article}
\begin{document}
<<fig.cap="This causes \\texttt{no problems.}", fig.scap="This causes \\texttt{no problems.}">>=
plot(1:10,10:1)
@
\end{document}
非常非常感谢 Yihui Xie 大大提高了我的工作效率和代码的可重用性!
关于knitr 和 Sweave 中 fig.cap 的 LaTeX 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18958063/