MWE......
\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\foreach \l [count=\i from 0] in {{Text 1}, {Text 2}, {Text 3}} {
\ifnum\i<2
\node [align=center, above] at (2*\i, 1.1) {\l};
\else
\node [align=center, above] at (3*(\i-1), 1.1) {\l};
\fi
}
\end{tikzpicture}
\end{document}
... 导致错误Package pgf Error: No shape named 3*(2-1 is known
。如何从计数器中减去一个数字?
答案1
问题在于括号。它们使解析器感到困惑。隐藏它们:
\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\foreach \l [count=\i from 0] in {{Text 1}, {Text 2}, {Text 3}} {
\ifnum\i<2
\node [align=center, above] at (2*\i, 1.1) {\l};
\else
\node [align=center, above] at ({3*(\i-1)}, 1.1) {\l};
\fi
}
\end{tikzpicture}
\end{document}