我试图实现在自定义tikz函数中根据输入数字选择不同风格的类。
但是,\ifnum命令似乎并没有像我预期的那样工作。我得到的错误信息是:
> thesis/image/outline_MWE.tex:46: Missing = inserted for ifnum.
<to be read again>
}
l.46 makeoutlinefig{1}
thesis/image/outline_MWE.tex:46: Missing number, treated as zero.
<to be read again>
}
l.46 makeoutlinefig{1}
MWE:
documentclass[varwidth=true]{standalone}
% input{../preamble.tex}
% input{../colors.tex}
usepackage{tikz}
usetikzlibrary{shapes,arrows,arrows.meta, calc, decorations.markings, backgrounds,fit,positioning,plotmarks, intersections, patterns, intersections,decorations.text,external,decorations.pathreplacing}
begin{document}
DeclareRobustCommand{makeoutlinefig}[1]{
centering
defthreebw{16.7cm}
begin{tikzpicture}
[auto, box/.style ={rectangle,
% font= tiny,
draw=black,
thick,
% fill=blue!30,
text width=3.0cm,
minimum width=1.5cm,
align=center,
rounded corners,
minimum height=2.0cm,
dashed, thick},
activebox/.style = {box, draw=red,
thick,solid},
node distance = 0.5cm,
]
node[style=ifnum#1=1 activeboxelse boxfi,
text width=threebw] (b1) at (0,0) {textbf{1. Chapter}};
node[style=ifnum#1=2 activeboxelse boxfi,
text width=threebw, below = of b1] (b2) {textbf{2. Chapter}} ;
draw [-Stealth,ultra thick] (b1) -- (b2);
end{tikzpicture}
}
makeoutlinefig{1}
end{document}
您可以避免这样的问题:
documentclass[varwidth=true]{standalone}
usepackage{tikz}
usetikzlibrary{shapes,arrows,arrows.meta, calc, decorations.markings, backgrounds,fit,positioning,plotmarks, intersections, patterns, intersections,decorations.text,external,decorations.pathreplacing}
begin{document}
DeclareRobustCommand{makeoutlinefig}[1]{
centering
defthreebw{16.7cm}
begin{tikzpicture}[
auto,
box/.style = {
rectangle,
draw=black,
thick,
text width=3.0cm,
minimum width=1.5cm,
align=center,
rounded corners,
minimum height=2.0cm,
dashed,
thick
},
activebox/.style = {
box,
draw=red,
thick,
solid
},
node distance = 0.5cm,
]
ifnum#1=1
defmystyle{activebox}
else
defmystyle{box}
fi
node[mystyle, text width=threebw] (b1) at (0,0) {textbf{1. Chapter}};
ifnum#1=2
defmystyle{activebox}
else
defmystyle{box}
fi
node[mystyle, text width=threebw, below = of b1] (b2) {textbf{2. Chapter}} ;
draw [-Stealth,ultra thick] (b1) -- (b2);
end{tikzpicture}
}
makeoutlinefig{2}
end{document}