我的主文档中mwe.tex
有一个使用包集成的 PGF/TikZ 图standalone
。此图包含多个框架,因此可以显示具有不同轴缩放/轴部分的多个轴。必须至少编译两次该图才能正确获得完整的图例。
是否可以将外部编译的数量定义为独立命令,例如作为独立命令的参数或作为构建/latex 选项的一部分?
% !TEX root = ./mwe.tex
% !TEX encoding = UTF-8
% --- Pgfplot ---
\begin{filecontents}[overwrite]{./tikzPlotStandalone.tex}
\documentclass[border=0pt]{standalone}
\usepackage{pgfplots}
\usepackage{amsmath}
\usepackage{siunitx}
\usepackage{xcolor}
\begin{document}
\definecolor{color1}{rgb}{0.0, 0.0, 1.0}
\definecolor{color2}{rgb}{1.0, 0.0, 0.0}
\definecolor{color3}{rgb}{0.0, 0.5, 0.5}
\definecolor{color4}{rgb}{0.5, 0.0, 0.5}
\begin{tikzpicture}
\pgfplotsset{
compat=newest,
width=14.5cm,
height=5.5cm,
scale only axis,
grid,
xmin=-5.5,
xmax=5.5,
tick align=outside,
}
% Frame 1
\begin{axis}[
xlabel={ $ x $ },
xtick pos=bottom,
ymin=-10.0,
ymax=10.0,
y axis line style={color1},
ytick style={color1},
yticklabel style={color1},
axis y line*=left,
ylabel={ $f_{1}(x)$ },
ylabel style=color1,
]
\addplot[
color=color1,
mark size=2.0pt,
mark=square*,
mark options={solid},
]{ -2 * x - 2 };
\label{tikzPlot1}
\end{axis}
% Frame 2
\begin{axis}[
color=color2,
scale only axis,
hide x axis,
ymin=-10.0,
ymax=30.0,
axis y line*=left,
ylabel={ $f_{2}(x)$ },
every outer y axis line/.style={xshift=-2.0cm},
every tick/.style={xshift=-2.0cm},
every y tick label/.append style={xshift=-2.0cm},
]
\addplot[
color=color2,
mark size=2.0pt,
mark=*,
mark options={solid,fill=color2},
]{ -3 * x + 9 };
\label{tikzPlot2}
\end{axis}
% Frame 3
\begin{axis}[
color=color3,
scale only axis,
hide x axis,
ymin=-5.0,
ymax=15.0,
ytick style={color3},
axis y line*=right,
ylabel={ $f_{3}(x)$ },
ylabel style=color3,
]
\addplot[
color=color3,
mark size=2.0pt,
mark=triangle*,
mark options={solid,fill=color3}
]{ 2 * x - 3 };
\label{tikzPlot3}
\end{axis}
% Frame 4
\begin{axis}[
scale only axis,
hide x axis,
ymin=-10.0,
ymax=10.0,
axis y line*=right,
tick align=outside,
every outer y axis line/.style={
color4, xshift=2.0cm,
},
every tick/.style={
color4, xshift=2.0cm,
},
every y tick label/.append style={
color4, xshift=2.0cm,
},
ylabel={ $f_{4}(x)$ },
ylabel style={color4},
legend pos=north east,
]
\addlegendimage{refstyle={tikzPlot2}} \addlegendentry{ \color{color2} $f_{2}(x)$ }
\addlegendimage{refstyle={tikzPlot1}} \addlegendentry{ \color{color1} $f_{1}(x)$ }
\addlegendimage{refstyle={tikzPlot3}} \addlegendentry{ \color{color3} $f_{3}(x)$ }
\addplot[
color=color4,
mark size=2.0pt,
mark=diamond*,
mark options={solid,fill=color4}
]{ 2 * x + 0 };
\addlegendentry{ \color{color4} $f_{4}(x)$ }
\end{axis}
\end{tikzpicture}
\end{document}
\end{filecontents}
% --- Main document ---
\documentclass{article}
\usepackage[margin=2.5cm]{geometry}
\usepackage{standalone}
\pagestyle{empty}
\begin{document}
\begin{figure}[tb]
\centering
\includestandalone[
width=1.0\textwidth,
mode=buildmissing,
build={latexoptions={-interaction=batchmode -shell-escape -halt-on-error -output-directory "./"}},
]{./tikzPlotStandalone}
\end{figure}
\end{document}