I'm making a report template that requires the list of authors to be presented in several different ways, one of which is a table that lists each author and provides a space for them to sign the printed version of the document.
I have an author list defined as
\newcommand{\reportAuthors}{Bob Jones,Sally Smith,Humpty Dumpty}
and am attempting to generate a table as follows:
\begin{tabular}{|b{4cm}|b{6cm}|b{4cm}|}
\hline
\multicolumn{3}{l}{\begin{Large}\textbf{Signatures}\end{Large}} \\ \hline
Approved by: & & Bob Jones \\ \hline
Approved by: & & Sally Smith \\ \hline
Approved by: & & Humpty Dumpty \\ \hline
\end{tabular}
I've attempted this with the \@for
command as follows:
\begin{tabular}{|b{4cm}|b{6cm}|b{4cm}|}
\hline
\multicolumn{3}{l}{\begin{Large}\textbf{Signatures}\end{Large}} \\
\hline
\makeatletter
\@for\authname:=\reportAuthors\do{%
Approved by: & & \authname \\
}
\makeatother
\end{tabular}
but this produces an error that \authname
is an undefined control sequence. If I remove the & &
so that there's no columns, the error goes away and it properly iterates and inserts each name... but of course that leaves me without the names in the right column as is required.
If I put the \authname
in the first column (not that this is what the template should have, but just to test things), then instead of the undefined control sequence I get 'Incomplete \ifx
'.
So firstly, what is causing \authname
to be undefined if I insert the &
characters? and secondly, how can I get around this?
Update: I've tried combining some info found elsewhere to try doing as Martin suggested in terms of trying to collect the rows outside the tabular
environment:
\newcommand{\tablecontent}{}
\makeatletter
\@for\signame:=\reportAuthors\do{%
\g@addto@macro\tablecontent{Approved by: & & \signame \\ \hline }%
}
\makeatother
\begin{tabular}{|b{4cm}|b{6cm}|b{4cm}|}
\hline
\multicolumn{3}{l}{\begin{Large}\textbf{Signatures}\end{Large}} \\
\hline
\tablecontent
\end{tabular}
Which fixes the error, but results in empty cells in the third column (where \signame
should be). I suspect this is due to my lack of understanding about expansion, and by the time it's getting expanded, the \signame
definition is out of scope. Fiddling with \edef
hasn't really helped so far, but perhaps someone can point out some flaws...?
\signame
is not expanded by the\g@addto@macro
. You can use\xappto
from theetoolbox
package which expands its content before it is appended. Then you should protect\` and
\hline` with\noexpand
.