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.

  • This can't work this way, because \foreach can't operate beyond `table cells' which form a TeX group – user31729 Sep 5 '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 5 '17 at 15:30
  • If you have is .csv list, you can make a table with csvsimple or datatool packages. – Bernard Sep 5 '17 at 15:35
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
    }
}

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.