TransWikia.com

foreach in path construction behaves differently whether start is node or coordinate

TeX - LaTeX Asked on May 25, 2021

In tikZ‘s manual, following code is proposed to illustrate usage of foreach inside a path construction command:

enter image description here

On the image below, this is figure (1). Strangely, when the starting point ((0,0) in the above example) is replaced by a named node (figure (2)), the result is completely different : the paths constructed in the loop no longer follow each other, they all start from the given node. Starting from named coordinates (figure (3)) again results in the wanted bahaviour.

enter image description here

documentclass[margin=1cm]{standalone}
usepackage{tikz}

begin{document}
(1) tikz draw (0,0) foreach x in {1,...,3} { -- (x,1) -- (x,0) };
(2) tikz {node (a) at (0,0) {}; draw (a) foreach x in {1,...,3} { -- (x,1) -- (x,0) };}
(3) tikz {coordinate (a) at (0,0); draw (a) foreach x in {1,...,3} { -- (x,1) -- (x,0) };}
end{document}

I couldn’t find anything about that in the manual. Maybe this cryptic line?

Note that the node and pic path commands also support the foreach
statement in special ways.

Now what should I do to be able to use such a construct but starting from a node?

Note : pgffor.sty 2020/01/08 v3.1.5b (3.1.5b)

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP