How can I force knitr to input a tikzpicture directly?

不羁的心 提交于 2020-02-04 04:46:46

问题


My aim is to produce a document by mixing hand-written .tex files and .tex files generated from an Rmarkdown file using knitr with figures rendered as tikzpicture.

How do I achieve the generated .tex file to simply contain

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

I am struggling with tikz as device. I tried the tikzDevice library as well as knitr::opts_chunk$set(dev="tikz") I managed to create a .tex file with a tikzpicture environment for every chunk. Unfortunately knitr rendered said .tex file to pdf and generated an \includegraphics command. The most annoying problem with that is, I need to copy-paste my header into options(tikzLatexPackages) redundantly or "TeX is unable to calculate metrics".

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.

来源:https://stackoverflow.com/questions/56041034/how-can-i-force-knitr-to-input-a-tikzpicture-directly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!