![无法使用 \foreach 和 \pic 生成的局部边界框](https://linux22.com/image/410201/%E6%97%A0%E6%B3%95%E4%BD%BF%E7%94%A8%20%5Cforeach%20%E5%92%8C%20%5Cpic%20%E7%94%9F%E6%88%90%E7%9A%84%E5%B1%80%E9%83%A8%E8%BE%B9%E7%95%8C%E6%A1%86.png)
我遇到了\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}