tikz array lookup
See “array operator” in the TikZ/PGF manual, page 927
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\newcommand{\myarray}{{"foo","bar","baz"}}
\begin{tikzpicture}[font=\sffamily]
\foreach\Color [count=\k] in {red!90!black, green!50!black, blue!90!black}
{
\node[color=\Color] at ($(0,\k)$){\pgfmathparse{\myarray[\k-1]}\pgfmathresult};
}
\end{tikzpicture}
\end{document}
Arrays are indexed starting from 0
An alternative to array
could be using two variables in foreach
.
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}[font=\sffamily]
\foreach \color/\t [count=\k] in {red!90!black/foo,
green!50!black/bar, blue!90!black/baz}
{
\node[color=\color] at ($(0,\k)$){\t};
}
\end{tikzpicture}
\end{document}