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.






\TempVarby using\pgfmathresult? Is there also anevaluateoption of some kind? – cmhughes Feb 13 '14 at 19:01evaluatething :) – cmhughes Feb 13 '14 at 19:01pgfmathtruncatemacro:) – percusse Feb 13 '14 at 19:46:)). I have a question: where can I find documentation about the use and math operations ofevaluate? – Pier Paolo Feb 13 '14 at 20:19\foreachand theevaluateoption is discussed there, if I remember correctly:)I'm too lazy to check, tonight. – jub0bs Feb 13 '14 at 21:22\pgfmathsetmacro(withoutint(...)), you get3.0instead of3. So the arrow goes ton3.0(anchor with angle0of noden3). – Paul Gaborit Dec 06 '14 at 15:20evaluate = {...} that you used without loading themathlibrary (where it seems to me it's defined)? – AndréC Aug 03 '20 at 08:14tikz/pgfdocument. This example loadstikzwhich loads all the math libraries it needs. – Peter Grill Aug 04 '20 at 08:19mathlibrary by default, you have to ask it, here is the problem becauseevaluate={...}syntax is only documented in this library. That's why I'm asking myself this question. – AndréC Aug 04 '20 at 08:27evaluate={…}used in foreach loops? – AndréC Aug 04 '20 at 16:28