Hi Joel,

unfortunately, it is not.

It can be used to assemble a string containing the *complete* tabular 
environment, however. Afterwards, the string can be evaluated by TeX -- 
and the tabular environment will never see or feel the \foreach.

This is advanced usage. Be warned that you may need further 
documentation (see below). But it is a safe way to accomplish the task 
at hand:

{%
     % initialize result ("global definition"):
     \gdef\result{%
         \begin{tabular}{ *{3}{c} }
         1 & 2 & 3    \\
     }%
     \foreach \x in {1,2,3}{
         % define token register 1 to be the concatenation of the 
contents of \result and \cmidrule:
         \toks1=\expandafter{\result
             \cmidrule}%
         % expanded definition + global (=\xdef):
         % define \result to be the concatenation of token register 1 
(which is not expanded)
         % and {\x-\x}  (including the braces). The \x will be expanded.
         \xdef\result{\the\toks1 {\x-\x}}%
     }
     % finally, append the \end{tabular}:
     \toks1=\expandafter{\result
         \end{tabular}%
     }%
     % and define \result to contain the contents of token register 1:
     \xdef\result{\the\toks1 }%
}%

% now, evaluate it
\result

Details about TeX's expansion control can be found in 
http://pgfplots.sourceforge.net/TeX-programming-notes.pdf
or any other TeX (not LaTeX) book.

Best regards

Christian

Am 15.12.2011 08:23, schrieb Joel:
> Hello,
>
> Is it possible to use the \foreach loop inside a tabular?. This minimal 
> examples fails:
>
> \usepackage{pgfplots, booktabs}
> \begin{document}
>
> \begin{tabular}{ *{3}{c} }
> 1&  2&  3    \\
> \foreach \x in {1,2,3}{
>      \cmidrule{\x-\x}
> }
> \end{tabular}
>
> \end{document}
>
> with the error:
>
> ! Emergency stop.
> \cmidrule ->\noalign
>                       {\ifnum 0=`}\fi \@ifnextchar [{\@cmidrule }{\@cmidrule 
> ...
>
>
> TIA,
> Joel.
>
>
> ------------------------------------------------------------------------------
> 10 Tips for Better Server Consolidation
> Server virtualization is being driven by many needs.
> But none more important than the need to reduce IT complexity
> while improving strategic productivity.  Learn More!
> http://www.accelacomm.com/jaw/sdnl/114/51507609/
> _______________________________________________
> Pgfplots-features mailing list
> Pgfplots-features@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/pgfplots-features


------------------------------------------------------------------------------
Learn Windows Azure Live!  Tuesday, Dec 13, 2011
Microsoft is holding a special Learn Windows Azure training event for 
developers. It will provide a great way to learn Windows Azure and what it 
provides. You can attend the event by watching it streamed LIVE online.  
Learn more at http://p.sf.net/sfu/ms-windowsazure
_______________________________________________
Pgfplots-features mailing list
Pgfplots-features@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pgfplots-features

Reply via email to