# Using \pgfplotsinvokeforeach in foreach loop

I am trying to run a \pgfplotsinvokeforeach loop in a \foreach loop to plot the variables var1_roll1 - var1_roll10 in one plot and var2_roll1 - var2_roll10 in another. Both loops work fine individually but a combination of both gives the following error:

! Illegal parameter number in definition of \pgffor@body.

Can anyone help? Here is the Code. Thanks!

\begin{figure}
\foreach \dt in {1,2} {
\begin{tikzpicture}
\begin{axis}[]
\pgfplotsinvokeforeach {1,2,...,10} {
}
\end{axis}
\end{tikzpicture}
}
\end{figure}

• Welcome to TeX.SX! Please help us to help you and add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. – user31729 May 28 '14 at 11:23

You don't need to use \pgfplotstableinvokeforeach in this case, simply nesting two ordinary \foreach loops works fine:

\documentclass{article}

\usepackage{pgfplots, pgfplotstable}

x var1_roll1 var1_roll2 var2_roll1 var2_roll2
1 10 11 20 21
2 10 11 20 21
}\datatable

\begin{document}
\begin{tikzpicture}
\begin{axis}
\foreach\dt in {1,2}{
\foreach\roll in {1,2}{