我遇到了\pic
和\foreach
中的一个问题Tikz
。下面是 MWE:
\documentclass[tikz]{standalone}
\tikzset{%
pics/abc/.style={%
code={
\node {this is some path};
}
}
}
\begin{document}
\begin{tikzpicture}
%local bounding box failed
\foreach \i in {1,2} \pic[local bounding box=\i] at (0,\i) {abc};
\draw(1)circle(1);
%local bounding box successful
\pic[local bounding box=3] at (10,4) {abc};
\draw(3)circle(1);
\end{tikzpicture}
\end{document}
当我使用和生成local bounding box
(1) 和 (2)时,会导致错误。但是当我直接使用 生成 (3)而不使用 时,就可以了。非常感谢您的帮助!\foreach
\pic
\draw(1)circle(1);
local bounding box
\pic
\foreach
\draw(3)circle(1);
答案1
您需要括号,并且可能需要添加键/.expanded
。我做了一些额外的更改来“现代化”您的代码。
\documentclass[tikz]{standalone}
\tikzset{%
pics/abc/.style={%
code={
\node {this is some path};
}
}
}
\begin{document}
\begin{tikzpicture}
%local bounding box failed
\path foreach \i in {1,2} {(0,\i) pic[local bounding box/.expanded=\i] {abc}};
\draw (1) circle [radius=1];
%local bounding box successful
\pic[local bounding box=3] at (10,4) {abc};
\draw(3)circle[radius=1];
\end{tikzpicture}
\end{document}