我对宏完全陌生。
我有代码,我想将其放入单独的命令中以避免代码重复
\documentclass{article}
\usepackage{graphicx}
\usepackage{balance} % for \balance command ON LAST PAGE (only there!)
\usepackage{tikz}
\usetikzlibrary{patterns, arrows,matrix,positioning, decorations.markings}
\usetikzlibrary{external}
\tikzset{external/force remake=true}
\tikzexternalize
\usepackage{environ}
\usepackage{textcomp}
\usepackage{gensymb}
%\usepackage[active,tightpage]{preview}
%\PreviewEnvironment{tikzpicture}
\NewEnviron{mytikz}[3][]%
{\begin{figure}[htp]
\centering
\begin{tikzpicture}[#1]
\BODY
\end{tikzpicture}
\caption{#2}%
\label{#3}%
\end{figure}%
}
\begin{document}
\section{Title}
\def\mycolor{blue}
% Stackboxes
% http://blog.dorian-depriester.fr/latex/tikz/empilements-de-cubes-sous-tikz
\newcommand{\elemcube}[4][white]
{
\draw [\mycolor,fill=#1!30, thin] (#2+1,#3,#4) -- ++(0,1,0) -- ++(0,0,1) -- ++(0, -1, 0) -- cycle;
\draw [\mycolor,fill=#1!40, thin] (#2,#3+1,#4) -- ++(1,0,0) -- ++(0,0,1) -- ++(-1, 0, 0) -- cycle;
\draw [\mycolor,fill=#1!30, thin] (#2,#3,#4) -- ++(1,0,0) -- ++(0,1,0) -- ++(-1, 0, 0) -- cycle;
}
\newcommand{\nicebox}[3]{
\def\latnum{#1}
\def\lonnum{#2}
\def\timenum{#3}
\foreach \time in{\timenum,...,0} {
\foreach \lon in{0,...,\lonnum} {
\elemcube{\latnum}{\lon}{\time}
}
}
}
\begin{mytikz}[x=(90:0.4cm), y=(0:0.4cm), z=(40:0.25cm), axis/.style={->,\mycolor,thick}]{Array example}{fig:ArrayExample}
\def\latnum{3}
\def\lonnum{3}
\def\timenum{6}
\nicebox{\latnum}{\lonnum}{\timenum}
\node[\mycolor,anchor=west] at (0,\lonnum+1,0.2) {\tiny $0$};
\node[\mycolor,anchor=west] at (0,\lonnum+1.8,0.2) {\tiny 1970 Jan 01};
\end{mytikz}
\end{document}
不幸的是,我有很多错误,包括
You can't use macro parameter character # in horizontal mode
请帮助正确定义命令
编辑:更新后的代码在外部化过程中挂起:pdflatex -synctex=1 -interaction=nonstopmode -shell-escape test.tex
在我的原始文档中,它会产生错误。但是,它可以与\nicebox{3}{3}{6}