我是 LaTex 新手,请耐心等待。
好的答案告诉你如何正确地使用\tikzexternalize
:
环境扩展和 Tikz 外部库的问题。
我的问题是:如何扩展代码以添加\caption
参数\label
?
编辑:感谢gernot
我的代码运行良好:
\NewEnviron{mytikz}[3][]%
{\begin{figure}[htp]
\centering
\begin{tikzpicture}[#1]
\BODY
\end{tikzpicture}
\caption{#2}%
\label{#3}%
\end{figure}%
}
% Elemcube command taken from: http://blog.dorian-depriester.fr/latex/tikz/empilements-de-cubes-sous-tikz
\newcommand{\elemcube}[4][white]
{
\draw [fill=#1!30,very thin] (#2+1,#3,#4) -- ++(0,1,0) -- ++(0,0,1) -- ++(0, -1, 0) -- cycle;
\draw [fill=#1!40,very thin] (#2,#3+1,#4) -- ++(1,0,0) -- ++(0,0,1) -- ++(-1, 0, 0) -- cycle;
\draw [fill=#1!10,very thin] (#2,#3,#4) -- ++(1,0,0) -- ++(0,1,0) -- ++(-1, 0, 0) -- cycle;
}
\begin{mytikz} [x=(90:0.2cm), y=(0:0.2cm), z=(40:0.1cm), axis/.style={->,blue,thick}]{A sample 3-d array.}{fig:flyx}
\def\xx{8}
\def\yy{8}
\def\zz{8}
\foreach \z in{\zz,...,0}
{
\foreach \x in{0,...,\xx}
{
\foreach \y in{0,...,\yy}
{
\elemcube{\x}{\y}{\z}
}
}
}
% draw axes
\draw[axis] (0,0,0) -- (\xx+1.5,0,0) node[anchor=north east]{$lat$};
\draw[axis] (0,0,0) -- (0,\yy+1.5,0) node[anchor=north west]{$lon$};
\draw[axis] (\xx+1,\yy+1,0) -- (\xx+1,\yy+1,\zz+1.5) node[anchor=south]{\large $time$};
\end{mytikz}
答案1
我想你不需要使用该xargs
包。在这种情况下,你可以定义一个mytikz
环境,就像
\usepackage{environ}
\NewEnviron{mytikz}[3][]%
{\begin{figure}[htp]
\centering
\begin{tikzpicture}[#1]
\BODY
\end{tikzpicture}
\caption{#2}%
\label{#3}%
\end{figure}%
}
并将其用作
\begin{mytikz}[tikz options for your drawing]{caption}{label}
... tikz commands ...
\end{mytikz}
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{external}
\tikzexternalize
\usepackage{environ}
\NewEnviron{mytikz}[3][]%
{\begin{figure}[htp]
\centering
\begin{tikzpicture}[#1]
\BODY
\end{tikzpicture}
\caption{#2}%
\label{#3}%
\end{figure}%
}
\begin{document}
\tikzset{external/force remake=true}
\begin{mytikz}[every path/.style={red}]{my caption}{figlabel}
\draw(0,0) circle (1cm);
\node {hello world};
\end{mytikz}
See my great figure~\ref{figlabel}.
\end{document}