Question.
Why does
\documentclass{amsart}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\foreach \index in {0,1,2,3}{
\node (v\index) at (\index cm, \index cm)[]{$v_{\index}$};
%\draw (v0)--(v1);
\draw (v0)--($(v0)+(1 cm,0 cm)$);
}
\end{tikzpicture}
\end{document}
compile, while
\documentclass{amsart}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\foreach \index in {0,1,2,3}{
\node (v\index) at (\index cm, \index cm)[]{$v_{\index}$};
\draw (v0)--(v1);
%\draw (v0)--($(v0)+(1 cm,0 cm)$);
}
\end{tikzpicture}
\end{document}
results in an error message
No shape named v1 is known.
?
Remark.
- I would also appreciate advice, if the present one is not recommendable, about how to make the name of a node depend on a loop variable.
- I simply do not see a reason for the above error message, neither from rereading the code, nor the manual, nor from reading discussions about naming nodes in TikZ---the node name seems to have been defined. I hope that this is not a bug, rather, that I am overlooking something easily fixed.
v1
without creating it before, when the foreach index is = 0