I am trying to learn \foreach in TikZ and I am confused because of all the errors I get.
Here is a code sample I tried that gave me:
ForeachEvaluateTest.tex:0:File ended while scanning use of \pgffor@stripcontext
\documentclass{article}
\usepackage{tikz}
\begin{document}
\pgfmathsetmacro{\dx}{5}
\pgfmathsetmacro{\offx}{2}
\begin{tikzpicture}
\pgfmathsetmacro{\endi}{\offx+\dx}
\pgfmathsetmacro{\starti}{\offx}
\foreach \i [evaluate=\i] in {\starti,...+1,\endi}
{
\draw (\i,0) -- (\i,1);
}
\end{tikzpicture}
\end{document}
I manage to fix this by a strange modification which can not possibly be the best way to fix it.
\documentclass{article}
\usepackage{tikz}
\begin{document}
\pgfmathsetmacro{\dx}{5}
\pgfmathsetmacro{\offx}{2}
\begin{tikzpicture}
\pgfmathsetmacro{\endi}{\offx+\dx-1}
\pgfmathsetmacro{\starti}{\offx-1}
\foreach \i [evaluate=\i] in {\starti+1,...+1,\endi+1}
{
\draw (\i,0) -- (\i,1);
}
\end{tikzpicture}
\end{document}
Any pointers to why this makes a difference?
\foreach \i [evaluate=\i as \j using int(\i+1)] in {\starti,...,\endi} { \draw (\j,0) -- (\j,1); }– Claudio Fiandrino Nov 04 '13 at 11:43