问题
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 <!-- -->.
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