[Tex/LaTex] Draw several horizontal lines using tikz

pgfmathtikz-pgf

I would like to draw 5 horizontal lines, each of length 0.5cm and separated by 0.2cm. I have the following code, however, instead of getting 5 individual lines, I get one long continous line. What could be the problem?

\documentclass{article}
\usepackage{tikz}
\usepackage{pgfmath}

\title{Horizontal Lines}

\begin{document}
\begin{tikzpicture}
\begin{scope}

\draw[-] (0,0) -- coordinate (a1) (0,0); %Draw first line

\foreach \x in {2,3,4,5}{
    %Compute next starting point. 0.7 = 0.5 (line length) + 0.2 (line spacing)
    \pgfmathparse{0 + (\x-1) * 0.7} 
    \draw[-] (\pgfmathresult,0) -- coordinate (a\x) (\pgfmathresult+0.5,0);
}
\end{scope}


\end{tikzpicture} 

\end{document}

Best Answer

The problem might be to further computation with the result of \pgfmathresult?. Despite the dash-patternof Torbjørn, another idea (which is i think more readable than the OPs approach) is the TikZ calclibrary

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}

\begin{document}
    \begin{tikzpicture}
        \foreach \x in {0,1,2,3,4}{
            \draw (.7*\x,0) -- coordinate(a\x) (.5+.7*\x,0);
        }
    \end{tikzpicture}
\end{document}