Consider the (currently incorrect) MWE:
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows,calc}
\begin{document}
\begin{tikzpicture}[node distance=2cm, auto]
\def\mypoints{(1, 0), (2, 0), (3, 0), (4, 0), (5, 0), (5, 1), (4, 1), (3, 1), (2, 1), (1, 1)};
\def\lastnode{(1,0)};
\foreach \x in \mypoints {
\draw[fill] \x circle (0.05);
\path[draw, -latex', black!50!white] \x -| \lastnode;
\let\lastnode=\x;
};
\end{tikzpicture}
\end{document}
My goal is to iterate through a list of points, either defined as such or generated through a \foreach
range, and draw a circle/node/rectangle/etc at each point and then draw an arrow or other line to that point from the previous iteration.
What I thought would work is to create a trailer
variable that maintains the state of the most recently drawn node, then use that information to draw the connecting lines easily. Currently the \lastnode
variable is not updating, most likely because I am using the wrong macro for the job...
Is it possible to use the above outlined method to draw and connect nodes/points/... iteratively, or is another approach more appropriate? Ideally, the solution would work with both points (x, y)
and named nodes (nodenumber1)
.