I'm trying to use a counter inside a TikZ picture, and use values resulting on calculations with this counter. Let's say for instance, I want i
to be ranging from 0 to 9, j
to be i*5
and k
to be i*10
. I've managed to get this working this way:
\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}
\foreach \i in {0,...,9}
{
\def \j {\pgfmathparse{\i * 5}\pgfmathresult}
\def \k {\pgfmathparse{\i * 10}\pgfmathresult}
\node at (0, -\i) {\tiny \i,\j,\k};
}
\end{tikzpicture}
\end{document}
This works as I intend to, the output being:
0,0.0,0.0
1,5.0,10.0
2,10.0,20.0
3,15.0,30.0
4,20.0,40.0
5,25.0,50.0
6,30.0,60.0
7,35.0,70.0
8,40.0,80.0
9,45.0,90.0
Now, and this is where it gets tricky, I want to use the secondary counter, let's say j
as a coordinate of the nodes:
\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}
\foreach \i in {0,...,9}
{
\def \j {\pgfmathparse{\i * 5}\pgfmathresult}
\def \k {\pgfmathparse{\i * 10}\pgfmathresult}
\node at (0, \j) {\tiny \i,\j,\k};
}
\end{tikzpicture}
\end{document}
I end up with this error:
! Incomplete \iffalse; all text was ignored after line 9.
<inserted text>
\fi
<*> mwe.tex
Why doesn't it work? What would be the proper way to achieve what I want to do?
\pgfmathsetmacro{\j}{\i*5}
etc (untested)