我注意到构建 pgf 图形是一个漫长的过程,每次构建文档时运行它都要花很长时间。相反,我想单独生成图形。
所以我写了这个:
\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{matrix}
\usetikzlibrary{arrows.meta}
\usetikzlibrary{backgrounds}
\usepgfplotslibrary{groupplots}
\pgfplotsset{compat=newest,
width=12cm,
height=2.5cm,
scale only axis=true,
max space between ticks=25pt,
every axis/.style={
axis y line=left,
axis x line=bottom,
axis line style={thick,->,>=latex, shorten >=-.4cm},
},
xtick=\empty,
every axis plot/.append style={thick},
tick style={black, thick},
}
\tikzset{
semithick/.style={line width=1.2pt},
}
\usetikzlibrary{external}
\tikzexternalize % activate!
\tikzset{external/force remake}
\begin{document}
\input{figure.pgf}
\end{document}
不幸的是,我得到的是整页而不是仅是与其大小相符的图形。
我应该如何生成该图形?
答案1
尝试此代码。使用\tikzexternalize
将生成全部第一次运行期间,tikz 图形将出现在您的文档中,因此新构建将运行得更快。(如果您每次都不强制重制!)
文件main.tex
(包含两个数字:width=7cm
,height=5cm
)
编译为
pdflatex.exe -synctex=1 -interaction=nonstopmode -shell-escape main.tex
% !TeX TS-program = pdflatex
%%% File main.tex
\documentclass{article}
\usepackage{showframe}% to see the margins <<<<
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usepgfplotslibrary{patchplots}% just for this plots
\pgfplotsset{compat=newest,
width=7cm, % <<<<<<<<<<<<<<<
height=5cm, % <<<<<<<<<<<<<<<
scale only axis=true,
max space between ticks=25pt,
every axis/.style={
axis y line=left,
axis x line=bottom,
axis line style={thick,->,>=latex, shorten >=-.4cm},
},
xtick=\empty,
every axis plot/.append style={thick},
tick style={black, thick},
}
\tikzset{
semithick/.style={line width=1.2pt},
}
\usetikzlibrary{external}
\tikzexternalize[% activate!
up to date check={simple}, % do not force remake every time!
]%
\begin{document}
\input{figure1.tex} %<<<<<<<<<<<<<<<<
\input{figure2.tex} %<<<<<<<<<<<<<<<<
\end{document}
figure1.tex
同一目录中的文件
%% file figure1.tex
\begin{tikzpicture}
\begin{axis}
\addplot3[
patch,patch refines=3,
shader=faceted interp,
patch type=biquadratic]
table[z expr=x^2-y^2]
{
x y
-2 -2
2 -2
2 2
-2 2
0 -2
2 0
0 2
-2 0
0 0
};
\end{axis}
\end{tikzpicture}
figure2.tex
同一目录中的文件
%% file figure2.tex
\begin{tikzpicture}
\begin{axis}[
title={Grids with shader=faceted interp}]
\addplot3[patch,patch type=biquadratic,
shader=faceted interp,patch refines=3]
coordinates {
(0,0,1) (6,1,1.6) (5,5,1.3) (-1,5,0)
(3,1,0) (6,3,0.4) (2,6,1.1) (0,3,0.9)
(3,3.75,0.5)
};
\end{axis}
\end{tikzpicture}
它将产生这个输出
同时将生成main-figure0.pdf
和,页面大小为。main-figure1.pdf
3.2x2.2in
第二次(更快)运行将输出消息
(figure1.tex
===== Image 'main-figure0' is up-to-date. ======
)
(figure2.tex
===== Image 'main-figure1' is up-to-date. ======
)