# tikz - align node vertically in foreach loop

I want to align nodes in foreach loop vertically!

\documentclass[border=10pt,convert={outfile=\jobname.png}]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usepackage{fmtcount}
\begin{document}
\begin{tikzpicture}[node distance=0]
\tikzset{box/.style={draw}}
\foreach \i [evaluate=\i as \p using \i-1] in {0,...,5} {
\ifnum\i=0
\else
\fi
}
\end{tikzpicture}
\end{document}


But now the output is:

I guess I should change the N\p to N\p.south west but it can not compile.

• \i as \p using int(\i-1) – percusse Feb 9 '17 at 21:56

The expression evaluate=\i as \p using \i-1 when \i > 0 results in 0.0, 1.0, 2.0, ..., 4.0 and you mean 0, 1, 2, ..., 4, so you can choose count=\p from -1 or as noted out by @percusse in a comment \i as \p using int(\i-1).

\documentclass[border=10pt,convert={outfile=\jobname.png}]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usepackage{fmtcount}
\begin{document}
\begin{tikzpicture}[node distance=0]
\tikzset{box/.style={draw}}
\foreach \i [count=\p from -1] in {0,...,5} {
\ifnum\i=0
\else
\fi
}
\end{tikzpicture}
\end{document}


• hmmm, sounds weird, that means in my code, N1.0 actually does exist, compile should report error then we can know it's not a valid node at all. – lucky1928 Feb 10 '17 at 2:38

You can use chain as below:

\documentclass[border=10pt,convert={outfile=\jobname.png}]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usepackage{fmtcount}
\usetikzlibrary{chains,shapes}

\begin{document}
\begin{tikzpicture}[start chain=values going below,node distance=0,outer sep=0]
\tikzset{box/.style={draw}}
\foreach \i [evaluate=\i as \p using \i-1] in {0,...,5} {