
Ich war mit einem Problem von \pic
und \foreach
in konfrontiert Tikz
. Unten ist ein 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}
Wenn ich local bounding box
(1) und (2) mit \foreach
und erzeuge \pic
, \draw(1)circle(1);
tritt ein Fehler auf. Aber wenn ich local bounding box
(3) direkt mit \pic
ohne erzeuge \foreach
, \draw(3)circle(1);
ist alles in Ordnung. Vielen Dank für jede Hilfe!
Antwort1
Sie benötigen Klammern und möchten möglicherweise den /.expanded
Schlüssel hinzufügen. Ich habe mehrere zusätzliche Änderungen vorgenommen, um Ihren Code zu „modernisieren“.
\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}