knitr 和 Sweave 中 fig.cap 的 LaTeX 错误

标签 latex knitr sweave figure

以下代码在 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/

相关文章:

r - 将针织临时文件附加到 R Shiny 的电子邮件

r - Knitr:将代码块中的文本打印为R markdown

emacs - 使用 Sweave 文档修改 Emacs 选项卡行为

pdf - gnuplot - pdf 终端 - 设置 unicode 字符(太阳质量符号/odot)

latex - 如何在Beamer中更改单个框架的页脚/边框?

latex - latex 中的多个图形带标题

vim-latex 套件,如何默认打开文件而不折叠文本

css - 使用 Foundation 4 CSS 时 R Markdown 绘制图像质量损失

r - 如何抑制 Sweave 中未被 echo=FALSE 抑制的输出?

sweave - xtable 标题中的标签用于在 lyx 中交叉引用