Die Verwendung des lokalen Begrenzungsrahmens, der durch \foreach und \pic erzeugt wurde, ist fehlgeschlagen.

Die Verwendung des lokalen Begrenzungsrahmens, der durch \foreach und \pic erzeugt wurde, ist fehlgeschlagen.

Ich war mit einem Problem von \picund \foreachin 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 \foreachund erzeuge \pic, \draw(1)circle(1);tritt ein Fehler auf. Aber wenn ich local bounding box(3) direkt mit \picohne 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 /.expandedSchlü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} 

Bildbeschreibung hier eingeben

verwandte Informationen