Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I want to create a graph of values I defined in an array using \drawwith TikZ. I am having troubles including the part of the draw-command generated by an \ForEach -loop (forarray-package), which works fine on its own.

Problem is at l.16 "! Package tikz Error: Giving up on this path. Did you forget a semicolon?."

\documentclass[12pt,a4paper]{article} 

\usepackage{forarray}
\usepackage{tikz} 

\begin{document}

\DefineArrayVar{leist}{@}{,}{0,1,2,3,4,5,6,7,8,9,10}{,}{8,7,8,9,7,6,9,9,8,9,9}

\newcommand{\coord}[1]{ --  (#1,\csname leist@#1\endcsname)}

\ForEach{,}{\coord{\thislevelitem}}{1,2,3,4,5,6,7,8,9,10};

\begin{tikzpicture}

\draw (0,0) \ForEach{,}{\coord{\thislevelitem}}{1,2,3,4,5,6,7,8,9,10};

\end{tikzpicture}

\end{document}
share|improve this question

1 Answer 1

I'd use the standard \foreach provide by TikZ:

\documentclass[12pt,a4paper]{article}

\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
\draw (0,0)
\foreach \x/\y in {1/7,2/8,3/9,4/7,5/6,6/9,7/9,8/8,9/9,10/9}
  { -- (\x,\y) } ;
\end{tikzpicture}

\end{document}

The problem with \ForEach is that it requires expansions and assignments that TikZ can't perform when doing a \draw. Its own \foreach has been specially designed for this purpose (and has a friendlier syntax).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.