Consider a table (regular tabular environment) with a fixed number of columns. I want to create a command that accepts a comma-separated list of strings, where the number of strings may differ between zero and the number of columns.
\begin{tabular}{llll}
\outputrow{ab cd,foo,3,5}\\ %all columns used
\outputrow{}\\ %no column used
\outputrow{1,2}\\ %two columns used
\end{tabular}
\outputrow{cvs-input}
should, in all cases, generate all columns (4 in this example). The actual column value should be generated by two additional commands: \emptycol
just outputs the content of an empty column, whereas \usercol{content}
generates the corresponding output of the provided user input. So the result of the above example should be
\begin{tabular}{llll}
\usercol{ab cd} & \usercol{foo} & \usercol{3} & \usercol{5} \\
\emptycol & \emptycol & \emptycol & \emptycol \\
\usercol{1} & \usercol{2} & \emptycol & \emptycol \\
\end{tabular}
The number of columns is static for a single table, but I need this solution for different cases with a different number of columns.
I first thought of using a package like etoolbox
, but I'm not sure how I can emit a single column using a loop or something like this.
Do you have any advice how this can be achieved?
\emptycol
really necessary? For example, row 2 might just as well have been\\
.\emptycol
, which at first glance would seem to indicate that it's supposed to generate an entire column. However, the code snippets you provide suggest that it's supposed to generate empty cells, not columns. Please clarify the purpose of this macro. Same goes for the name of\usercol
.