I wish to loop over this code:
\begin{tabular}{l*{8}c}
first column &
column a &
column b &
column c &
column d &
column e &
column f &
column g
\end{tabular}
But the following does not compile:
\begin{tabular}{l*{8}c}
first column
\foreach \i in {a,b,c,d,e,f,g,h}{%
& column \i%
}
\end{tabular}
with an error that looks nothing like something I've written:
! Extra }, or forgotten \endgroup.
<template> \unskip \hfil }
\hskip \tabcolsep \endtemplate
l.40 }
I've hope for a while that this post would help, but I'm not sure that this part of the question was finally answered there.
How do I make this loop work?
\foreach
each table cell is a group and&
is like}{
which ends one group and starts a new one, at which point the internal state of the loop is lost. You either need a different loop system that doesn't require local definitions or just build up a macro with the table row then execute that macro at the end of the loop.\endgroup
:) What "different loop system" are you thinking about? Also, I'm not sure I understand what you mean by "build a macro with the table row" :\