首页 > 解决方案 > 如何强制 knitr 直接输入 tikzpicture?

问题描述

我的目标是通过将手写的 .tex 文件和使用 knitr 从 Rmarkdown 文件生成的 .tex 文件与呈现为 tikzpicture 的图形混合来生成文档。

如何实现生成的 .tex 文件以简单地包含

\begin{figure}
  \input{unnamed-chunk-1-1.tex}
\end{figure}

我正在努力将 tikz 作为设备。我尝试了该tikzDevice库,并knitr::opts_chunk$set(dev="tikz")设法为每个块创建了一个带有 tikzpicture 环境的 .tex 文件。不幸的是,knitr 将所述 .tex 文件渲染为 pdf 并生成了一个\includegraphics命令。最烦人的问题是,我需要将我的标题复制粘贴到options(tikzLatexPackages)冗余或“TeX 无法计算指标”中。

Additionally I did not manage to put the graphics into a figure environment. If I simply enclose the chunk with \begin{figure} and \end{figure}, it will not include the pdf at all anymore and replace the command with ![](figures/unnamed-chunk-1-1.pdf)<!-- -->.

After going through the Rmarkdown documentation, I tried setting the chunkoption external=TRUE, but that had no effect.

EDIT: The environment should be generated when setting the chunk option fig.env='figure', but like external=TRUE, that had no effect on the generated .tex file.

标签: rstudior-markdownknitrtikz

解决方案


推荐阅读