如何正确使用 standalone?standalone 和 \input 之间的缩放问题

如何正确使用 standalone?standalone 和 \input 之间的缩放问题

我必须处理多个相当大的 tikz 图像,我想将它们作为独立文件单独运行。现在,当将这些图像集成到我的主文件中时,缩放功能关闭了。这意味着我根据是否使用

\includestandalone[mode=buildnew]{...}

或者

\input{...}

我附加了一个最小工作示例来说明我的问题:

主文件:

\documentclass[10pt, conference]{IEEEtran}
 \usepackage{tikz,pgfplots,pgfplotstable}
\usepackage{standalone}
\begin{document}
\includestandalone[mode=buildnew]{images/FullPlot}
\input{images/FullPlot}
\end{document}

子文件夹 .../images/ 中的 tikz-image 文件

\documentclass[tikz]{standalone}
\usepackage{pgfplots,pgfplotstable,amsmath}
\pgfplotsset{compat=1.17}
\begin{document}
\begin{tikzpicture}
\begin{axis}[%
width=0.85\columnwidth]
\node at (1,1) {SampleText};
\addplot [color=black, forget plot]
  table[row sep=crcr]{%
0   0\\ 2 2\\
};
\end{axis}
\end{tikzpicture}%
\end{document}

我怎样才能让独立图像遵循主文件的格式,即本例中主类的两列和通用格式?最终,我只希望独立图像产生与 \input 相同的结果,但相比之下,如果我更改了上次的任何内容,则仅编译文件。还有其他最佳实践值得注意吗?

我非常感谢任何有用的答案和评论!

答案1

如果您正在寻找的结果\input不是每次 TeX 都编译此外部文件,那么我会查看 tikzexternalise tikz 库。

\usetikzlibrary{external}

它会单独编译文档中的任何 tikz,并将结果保存在缓存文件夹中。每个 tikz 图片仅在对该图片进行更改时才会更新。您无需更改 LaTeX 代码中的任何内容,并且它可以与外部和内部 tikz 文件一起使用。

要求 LaTeX 启用 shell escape。例如:

pdflatex -synctex=1 -interaction=nonstopmode --shell-escape %.tex

我发现它有时有点不稳定,但它大大加快了包含许多 tikz 图表和绘图的文档的编译速度。

答案2

基本上,独立包所做的一切都是\input忽略所有通常会导致错误的代码(\documentclass ... \begin{document}以及相应的\end{document})。它确实不是使用 shell-escape 独立运行。

如果您使用文档类相关值(如\columnwidth)并且想要重复使用该图像,则需要将该信息提供给独立源。最简单的方法是手动。

\documentclass[tikz]{standalone}
\usepackage{pgfplots,pgfplotstable,amsmath}
\pgfplotsset{compat=1.17}
\AtBeginDocument{\columnwidth=252pt}% depends on document class
\begin{document}
\begin{tikzpicture}
\begin{axis}[%
width=0.85\columnwidth]
\node at (axis cs: 1,1) {\the\columnwidth};
\addplot [color=black, forget plot]
  table[row sep=crcr]{%
0   0\\ 2 2\\
};
\end{axis}
\draw[red] (current bounding box.south west) rectangle (current bounding box.north east);
\end{tikzpicture}%
\end{document}

由于无论如何您都需要运行上述构建,因此您不妨在主文档中使用\includegraphics而不是。\includestandalone

\documentclass[10pt, conference]{IEEEtran}
\usepackage{graphicx}
\usepackage{tikz,pgfplots,pgfplotstable}% for \input version
\usepackage{standalone}% for \input version
\usepackage{showframe}
\begin{document}
\noindent\includegraphics{test6}

\noindent\input{test6}% for comparison
\end{document}

相关内容