我曾就 Sweave
提出过类似的问题(
Dynamic references to figures in a R comment within Sweave document
)并想看看是否有人在使用 knitr
时给出类似的答案。
目标是拥有以下代码块
<<"example", fig.cap = "some figure", highlight = FALSE>>=
# the following code generated Figure \ref{fig:example}
plot(1:10, 1:10)
@
在生成的 .pdf 中显示为
# the following code generated Figure 1.1
plot(1:10, 1:10)
到目前为止,我发现通过设置 highlight = FALSE
,R 代码会被放入生成的 .tex 文件中的 verbatim
环境中。如果环境可以是 alltt
而不是 verbatim
那么我们就会得到所需的输出。是否可以通过 knitr
选项将非突出显示的代码块放置在 alltt
环境中?
最佳答案
我添加了一个示例 072-latex-reference.Rnw在 knitr-examples
存储库中。基本思想是恢复转义的 \ref{}
(默认输出中应该是 \textbackslash{}ref\{\}
)。
关于r - R 注释中的动态 LaTeX 引用与knitr,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14058832/