将 tikzexternalize 与 tikzscale 和 trim axis 结合起来

将 tikzexternalize 与 tikzscale 和 trim axis 结合起来

尝试构建以下内容会导致 pdflatex 挂起并一遍又一遍地构建文件:

% !TEX options=--shell-escape
\documentclass{article}
\usepackage[english]{babel}
\usepackage{pgfplots}
\usepackage{tikzscale}
\usepgfplotslibrary{external}
% \tikzexternalize  % !!! B
\pgfplotsset{compat=1.16}

\begin{document}
\begin{filecontents}[overwrite]{tex-stackexchange.tikz}
\begin{tikzpicture}
[trim axis left, trim axis right]  % !!! A
\begin{axis}[
  width=\textwidth,
  height=0.25\textwidth,
  xmin=0, xmax=5, ymin=0, ymax=5]
\addplot coordinates { (1,1) (2,3) (3,2) (4.5,4) };
\end{axis}
\end{tikzpicture}
\end{filecontents}

\begin{figure}
\includegraphics[width=\textwidth]{tex-stackexchange.tikz}
\end{figure}

This is a lot of text. This is a lot of text. This is a lot of text.
This is a lot of text. This is a lot of text. This is a lot of text.
This is a lot of text. This is a lot of text. This is a lot of text.

\end{document}

注释掉标记的行!!! A可以使所有内容正确呈现,但没有外部化:

预期的

注释掉标记的行!!! B使得外部化看起来有效,但现在绘图的宽度是错误的。

注释掉任何内容都不会导致 pdflatex 挂起。


这个问题可能看起来相关,但是:

  • 要求获得的行为不是使用trim axis
  • 没有得到关于externalize标题的答案

答案1

据我所知,你只需要使用该mode=list and make选项。当然,你还需要执行 make 文件,提示符会告诉你在你的机器上要做什么(希望如此;-)。

\documentclass{article}
\usepackage[english]{babel}
\usepackage{pgfplots}
\usepackage{tikzscale}
\usepgfplotslibrary{external}
\tikzexternalize[mode=list and make]  % !!! B
\pgfplotsset{compat=1.16}

\begin{document}
\begin{filecontents}[overwrite]{tex-stackexchange.tikz}
\begin{tikzpicture}
[trim axis left, trim axis right]  % !!! A
\begin{axis}[
  width=\textwidth,
  height=0.25\textwidth,
  xmin=0, xmax=5, ymin=0, ymax=5]
\addplot coordinates { (1,1) (2,3) (3,2) (4.5,4) };
\end{axis}
\end{tikzpicture}
\end{filecontents}

\begin{figure}
\includegraphics[width=\textwidth]{tex-stackexchange.tikz}
\end{figure}

This is a lot of text. This is a lot of text. This is a lot of text.
This is a lot of text. This is a lot of text. This is a lot of text.
This is a lot of text. This is a lot of text. This is a lot of text.

\end{document}

在此处输入图片描述

相关内容