# Using line thickness as a loop variable in TikZ

Here is a very simple code that mysteriously does not work; a simple pgf loop where the first variable is the y-coordinate and the second variable is the line thickness. LaTeX rejects the thickness saying "I do not know the key '/tikz/ thin"

My code:

\documentclass[tikz, border=0.3cm]{standalone}
\begin{document}
\begin{tikzpicture}

\path (0,0) coordinate (current); %start point
\foreach \ylabel / \labelthickness in {1 / thin , 2 / thick , -4 / semithick }
{
\draw [\labelthickness] (current) -- +(1,\ylabel) coordinate (current) ;
}
\end{tikzpicture}
\end{document}


Please give some explanation why my code does not work, I am clueless.

• It doesn't like the space. Try 1/thin,2/thick....
– cfr
Oct 25, 2015 at 16:29
• @cfr: Thanks! Wow, that's crazy, the expression is so space sensitive! Even if I write {1/thin,2/thick,-4/semithick } it would complain about the space behind semithick. Oct 25, 2015 at 18:07

TikZ is interpreting the spaces as part of the keys which is why it doesn't recognise /tikz/ thin. Fortunately, it knows all about /tikz/thin:

\documentclass[tikz,border=10pt,multi]{standalone}
\begin{document}
\begin{tikzpicture}
\path (0,0) coordinate (current); %start point
\foreach \ylabel / \labelthickness in {1/thin,2/thick,-4/semithick}
{
\draw [\labelthickness] (current) -- +(1,\ylabel) coordinate (current) ;
}
\end{tikzpicture}
\end{document}