5

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}
5

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).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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