# How to create a table macro that takes more than 10 arguments

I want to create a macro that creates several tables. In the example below, the command that creates the tables \chungeltable will use one argument for each column in the table (More than 10 columns). Each argument contains a comma separated list which has to be the information of each row:

\chungeltable{1,2,3}{a,b,c}{one,two,three}{uno,dos,tres}{um, dois, três}{um,dois,treis}{Eins,zwei,drei}{Ett, två, tre}{un, deux, trois}{En, to, tre}

I'm using the following approach (See My previous question).

However, as it is not possible to define more than 10 arguments I am getting the error:

"kernel/bad-number-of-arguments"Function '\chungeltable' cannot be defined with 10 arguments"

Here is my table:

\documentclass{article}
\usepackage[a4paper,landscape]{geometry}
\usepackage{multirow,longtable}
\usepackage{xparse}

\NewDocumentCommand{\chungeltable}{mmmmmmmmmmm}
{%
\begingroup\scriptsize
\begin{longtable}{ | p{4cm} | p{3cm} | *{13}{l|} p{3cm} | }

\hline
\multirow{3}{*}{Name} &
\multirow{3}{*}{Description} &
\multicolumn{14}{c|}{Observation} \\
\cline{3-16}
&  & \multicolumn{3}{c|}{A} & \multicolumn{3}{c|}{B}  &    \multicolumn{2}{c|}{C} &
\multicolumn{2}{c|}{D} & E & \multirow{2}{*}{F} & \multirow{2}{*}{G} & \multirow{2}{*}{Other} \\
\cline{3-13}
&  & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 & 13 & & & \\ \hline
\chungeltablebody{#1}{#2}{#3}{#4}{#5}{#6}{#7}{#8}{#9}{#a}{#b}
\end{longtable}
\endgroup
}

\ExplSyntaxOn
\NewDocumentCommand{\chungeltablebody}{mmmmmmmmmmm}
{
\tl_clear:N \l_tmpa_tl
\int_step_inline:nnnn { 1 } { 1 } { \clist_count:n { #1 } }
{
\tl_put_right:Nx \l_tmpa_tl
{
\clist_item:nn { #1 } { ##1 } &
\clist_item:nn { #2 } { ##1 } &
\clist_item:nn { #3 } { ##1 } &
\clist_item:nn { #4 } { ##1 } &
\clist_item:nn { #5 } { ##1 } &
\clist_item:nn { #6 } { ##1 } &
\clist_item:nn { #7 } { ##1 } &
\clist_item:nn { #8 } { ##1 } &
\clist_item:nn { #9 } { ##1 } &
\clist_item:nn { #a } { ##1 } &
\clist_item:nn { #b } { ##1 }
&  &  &  &  &
\exp_not:n { \\ \hline }
}
}
\tl_use:N \l_tmpa_tl
}
\ExplSyntaxOff

\begin{document}

\chungeltable{1,2,3}{a,b,c}{one,two,three}{uno,dos,tres}{um, dois, três}{um,dois,treis}{Eins,zwei,drei}{Ett, två, tre}{un, deux, trois}{En, to, tre}

\end{document}

My question is: How can I define more than 10 arguments in a table, where each argument represents the columns of the table and each item in the list represents the information in the rows?

• I knew we'd arrive to this. You're taking a wrong approach to the matter. – egreg May 19 '17 at 15:13
• the syntax #1 to #9 and the limit to at most 9 arguments is built in to tex and can not be extended in a macro package such as latex. – David Carlisle May 19 '17 at 15:20
• Not entirely sure what you are trying to do but this might be related: tex.stackexchange.com/questions/367892/… – Andrew May 19 '17 at 15:20
• @egreg Is it possible to parse the commands in \chungeltablebody with other command? like here If not, which approach would you recommend for a longtable like this? – Chüngel May 19 '17 at 16:42
• Does it have to work in longtable? That is, does it have to span across page boundaries? – Steven B. Segletes May 22 '17 at 12:44

While the question asks about absorbing more than 10 arguments, the real motivation of the OP, looking at the question, is "how to input tabular data by column, rather than by row, including for cases that exceed 9 columns?"

Being no expert in multicolumn and multirow, I don't know how to restore the final vertical line after the last column of the table, but here, I show how to digest a table by column, rather than by row, even if the number of columns exceeds 9.

I use the listofitems package to parse the column-wise data, and then set up a double loop to transpose the data into the standard row-wise format and place it in the token register \transposedtoks. Finally, I just regurgitate \the\transposedtoks into the long table. I show it here with 13 columns.

Data input format is currently

\chungeltable{1,2,3&a,b,c&one,two,three&uno,dos,tres&um, dois, três&
um,dois,treis&Eins,zwei,drei&Ett, två, tre&un, deux, trois
&En, to, tre&eleven,th,col&twelve,th,col&thirteen,th,col}

however, the & column separator and , row separator can be changed by editing the line \setsepchar{&/,}. The listofitems magic occurs in the macro \transposedata.

\documentclass{article}
\usepackage[a4paper,landscape]{geometry}
\usepackage{multirow,longtable}
\usepackage{xparse}
\usepackage{listofitems}
\NewDocumentCommand{\chungeltable}{m}
{%
\transposedata{#1}%
\begingroup\scriptsize
\renewcommand\arraystretch{1.1}
\begin{longtable}{ | p{4cm} | p{3cm} | *{13}{l|} p{3cm} | }
\hline
\multirow{3}{*}{Name} &
\multirow{3}{*}{Description} &
\multicolumn{14}{c|}{Observation} \\
\cline{3-16}
&  & \multicolumn{3}{c|}{A} & \multicolumn{3}{c|}{B}  &    \multicolumn{2}{c|}{C} &
\multicolumn{2}{c|}{D} & E & \multirow{2}{*}{F} & \multirow{2}{*}{G} & \multirow{2}{*}{Other} \\
\cline{3-13}
&  & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 & 13 & & & \\ \hline
\the\transposedtoks
\end{longtable}
\endgroup
}
\newtoks\transposedtoks
\newcommand\transposedata[1]{%
\transposedtoks{}%
\setsepchar{&/,}%
\foreachitem\y\in\rawdata[1]{%
\foreachitem\x\in\rawdata[]{%
\ifnum\xcnt>1\transposedtoks\expandafter{\the\transposedtoks&}\fi%
\edef\tmp{\rawdata[\xcnt,\ycnt]}%
\expandafter\transposedtoks\expandafter\expandafter\expandafter{%
\expandafter\the\expandafter\transposedtoks\tmp}%
}%
\transposedtoks\expandafter{\the\transposedtoks\\\hline}%
}%
}
\begin{document}
\chungeltable{1,2,3&a,b,c&one,two,three&uno,dos,tres&um, dois, três&um,dois,treis&Eins,zwei,drei&Ett, två, tre&un, deux, trois
&En, to, tre&eleven,th,col&twelve,th,col&thirteen,th,col}
\end{document}

Here is an example of using \transposedata, without all the chungeljumbo:

\documentclass{article}
\usepackage{listofitems}

\newtoks\transposedtoks
\newcommand\transposedata[2][&/,]{%
\setsepchar{#1}%
\transposedtoks{}%
\foreachitem\y\in\rawdata[1]{%
\foreachitem\x\in\rawdata[]{%
\ifnum\xcnt>1\transposedtoks\expandafter{\the\transposedtoks&}\fi%
\edef\tmp{\rawdata[\xcnt,\ycnt]}%
\expandafter\transposedtoks\expandafter\expandafter\expandafter{%
\expandafter\the\expandafter\transposedtoks\tmp}%
}%
\transposedtoks\expandafter{\the\transposedtoks\\\hline}%
}%
}
\begin{document}
\transposedata[&/\\]{a\\b\\c&d\\e\\f}
\begin{tabular}{|c|c|}
\hline
\the\transposedtoks
\end{tabular}
\end{document}