In many \foreach
iterative procedures in TikZ I would like to relate the generic node called n\x
-- where x
is a natural number -- to another node the name of which is obtained by applying basic mathemathical relationships to the number used in the name of the former.
Just to be clear, I wolud like to let's say draw a line from n\x
to n\x+1
or to n\x*2
or to n\x-3
, etc. So if x=4
I would like to draw lines like:
(n4)--(n5)
(n4)--(n8)
(n4)--(n1)
Is this possible?
In the following MWE I would like to draw lines between the nodes using an iterative procedure as previously mentioned.
\documentclass{article}
\usepackage{tikz}
%\usetikzlibrary{calc} <-- Would it be necessary?
\begin{document}
\begin{tikzpicture}
\matrix[column sep=1cm]{
\node (n1) {1}; & \node (n2) {2}; & \node (n3) {3}; & \node (n4) {4};\\
};
%\foreach \x in {1,...,3} <-- Something like this
%\draw (n\x)--(n\x+1);
\end{tikzpicture}
\end{document}
EDIT: This might be related, especially the comment at the end by @Mark Wibrow, but I can't get it to work.