条件选择tikz风格类
Conditional selection of tikz style classes
我尝试实现根据输入数字在自定义的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
\def\threebw{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 activebox\else box\fi,
text width=\threebw] (b1) at (0,0) {\textbf{1. Chapter}};
\node[style=\ifnum#1=2 activebox\else box\fi,
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
\def\threebw{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
\def\mystyle{activebox}
\else
\def\mystyle{box}
\fi
\node[\mystyle, text width=\threebw] (b1) at (0,0) {\textbf{1. Chapter}};
\ifnum#1=2
\def\mystyle{activebox}
\else
\def\mystyle{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}
我尝试实现根据输入数字在自定义的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
\def\threebw{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 activebox\else box\fi,
text width=\threebw] (b1) at (0,0) {\textbf{1. Chapter}};
\node[style=\ifnum#1=2 activebox\else box\fi,
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
\def\threebw{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
\def\mystyle{activebox}
\else
\def\mystyle{box}
\fi
\node[\mystyle, text width=\threebw] (b1) at (0,0) {\textbf{1. Chapter}};
\ifnum#1=2
\def\mystyle{activebox}
\else
\def\mystyle{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}