I tried to find an answer to this but currently I have no idea how to get it to work.
I want to create a new command which fills some lines of a tabular based on a given list with variable length like
\makeTabularRows{item1, item2, item3}
The output of this should be
\multicolumn{3}{c}{item1} & \\
\multicolumn{3}{c}{item2} & \\
\multicolumn{3}{c}{item3} &
So that it fits in a tabular like
\begin{tabular}{lclr}
\makeTabularRows{item1, item2, item3}
\end{tabular}
I found a lot of partial solutions for example this short one
\newcommand{\makeTabularRows}[1]{%
\def\nextitem{\def\nextitem{.}}%
\@for \el:=#1\do{\nextitem\el}%
}
to insert dots between the elements and other solutions looking more complex for example to create an enumeration. I found out that one problem is to include the & sign and my tests showed me that even inserting the \\ seems to be not possible. I am lost to find a solution for the tabular if there is one.
Any ideas how this can be done?
\multicolumn
?&
all definitions will be lost (for the next cell). You either need a purely expandable loop or some other possibly non expandable but cunning macro. There are expandable loops in the LaTeX kernel. (and you can do what you want with non expandable\xintFor
macro from packagexinttools
).#
but anyhow I don't think it could work (now that I have read your question for real ;-) ). See answer.