Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error of foreach and node commands #1313

Closed
psparkmath opened this issue Mar 26, 2024 · 4 comments
Closed

Error of foreach and node commands #1313

psparkmath opened this issue Mar 26, 2024 · 4 comments

Comments

@psparkmath
Copy link

Brief outline of the bug

I found that foreach command does not work well for \node.

I wrote the code \draw (P1) foreach \n in {2,3}{ -- (P\i) }; to draw lines connecting nodes P1, P2, P3, consecutively. But, this code draw lines connecting P1 and P2 and connecting P1 and P3.

If you change \node part to \coordinate, then foreach command works well.

Minimal working example (MWE)

\documentclass{article}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
\foreach[count=\i] \n in {1,3,2}{
    \node (P\i) at (\i,\n) {P\i};
%   \coordinate (P\i) at (\i,\n);
%   \node at (P\i) {P\i};
}
%\draw (P1) -- (P2) -- (P3);
\draw (P1) foreach \i in {2,3}{ -- (P\i)}; % <--- HERE!
\end{tikzpicture}
\end{document}
@jasperhabicht
Copy link

This is actually well-known. See, for example: https://tex.stackexchange.com/a/75152/47927

@hmenke
Copy link
Member

hmenke commented Mar 26, 2024

As documented.

image

There is an undocumented option foreach[scope iterations=false] but it's undocumented for a reason, namely that in most of the cases it's broken.

@hmenke hmenke added the pgffor label Mar 26, 2024
@muzimuzhi
Copy link
Member

Would be fixed by #1304 too?

@hmenke
Copy link
Member

hmenke commented Mar 27, 2024

Yes. It's also a duplicate of #356 and #1303 and closely related to #1047.

@hmenke hmenke closed this as completed Mar 27, 2024
loopspace added a commit to loopspace/pgf that referenced this issue Apr 12, 2024
This commit adds more information to what TikZ remembers between foreach
iterations, and does so in a way that makes it easier to add other
macros and dimensions to the list of things it remembers, both at the
code level and via keys.

Fixes pgf-tikz#356, pgf-tikz#1047, pgf-tikz#1303, pgf-tikz#1313

Signed-off-by: Andrew Stacey <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

4 participants