[Tex/LaTex] 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!

\foreach \dt in {1,2} {
           \pgfplotsinvokeforeach {1,2,...,10} { 
            \addplot[]  table[x=x,y=var\dt_roll#1] {../plot/test.txt};

Best Answer

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


\usepackage{pgfplots, pgfplotstable}

x var1_roll1 var1_roll2 var2_roll1 var2_roll2
1 10 11 20 21
2 10 11 20 21

\foreach\dt in {1,2}{
    \foreach\roll in {1,2}{
        \addplot table [y=var\dt_roll\roll]{\datatable};