1

I want to build a table form a list (using pgffor package):

\newcommand{\tablecontent}{
    \foreach \theproduct in \productlist {                                                     
        \getproductcount{\theproduct} &                                                          
        \getproductdescr{\theproduct} &                                                          
        \getproductprice{\theproduct}\\\hline                                                    
    }
}

And then use it to create a table like this:

\begin{tabularx}{\textwidth}{c|c|c}
     .... \\% title row
     \tablecontent
     .... \\% total row
\end{tabularx}

But I have the following error: Extra }, or forgotten \endgroup.

dok
  • 51
  • This can't work this way, because \foreach can't operate beyond `table cells' which form a TeX group –  Sep 05 '17 at 14:57
  • Hi, welcome. There have been several questions here on the site about using loops to create tables before, if you search a bit perhaps you can find something useful. – Torbjørn T. Sep 05 '17 at 15:30
  • If you have is .csv list, you can make a table with csvsimple or datatool packages. – Bernard Sep 05 '17 at 15:35

1 Answers1

1

Thanks to this previous answer.

I found a solution to my problem, by using another loop iterator form xintootls. Note that \xintFor doesn't allow usage of \edef, but works in tabular environment.

\usepackage{xinttools}
\newcommand{\printproducts}{
    \xintFor ##1 in {\productlist} \do{
        \getproductcount{##1} &
        \getproductdescr{##1} &
        \getproductprice{##1}\\\hline
    }
}
dok
  • 51