我遇到了\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}
當我使用and生成local bounding box
(1) 和 (2)時,會導致錯誤。但是當我直接使用without生成(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}