# Table Macro with 2 or more arguments

I'm building a table using input from a coma separated list. (See My previous question). Now, I would like to have a command with two arguments (one argument for each name and one argument for each definition):

For example:

 \begin{document}
\chungeltable{One, Two, Three, Four}{this is the definition for the One, this is the definition for the Two, this is the definition for the Third, this is the definition for the fourth}
\end{document}


The following prints all items present in the second argument for each occurrence of the first argument given in \chungeltable.

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

\NewDocumentCommand{\chungeltable}{mm}
{%
\begin{center}\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}
\end{longtable}
\end{center}
}

\ExplSyntaxOn
\NewDocumentCommand{\chungeltablebody}{mm}
{
\tl_clear:N \l_tmpa_tl
\clist_map_inline:nn {#1, #2}
{
\tl_put_right:Nn \l_tmpa_tl { ##1 & #2  &  &  &  &  &  &  &  &  &  &  &  &  &  & \\\hline }
}
\tl_use:N \l_tmpa_tl
}
\ExplSyntaxOff


How can I fix this so that it prints each item of the first argument in the first column (Name) and each item of the second argument in the second column (Description)?

• Your code is incomplete – user31729 May 12 '17 at 16:05
• Sorry, but it's unclear what the code is supposed to do. – egreg May 12 '17 at 16:05
• Are you perhaps wanting to specify the table by columns instead of by rows? – egreg May 12 '17 at 16:07
• Hi, I would like to fill in e.g. the second table column using a second comma separated list. \chungletable{}{} – Chüngel May 12 '17 at 16:19
• unreleated to the question but don't put longtable in \begin{center} it won't centre it, just add spurious vertical space. – David Carlisle May 12 '17 at 16:34

You have to select one item at a time from both lists:

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

\NewDocumentCommand{\chungeltable}{mm}
{%
\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}
\end{longtable}
\endgroup
}

\ExplSyntaxOn
\NewDocumentCommand{\chungeltablebody}{mm}
{
\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 } &
&  &  &  &  &  &  &  &  &  &  &  &  &
\exp_not:n { \\ \hline }
}
}
\tl_use:N \l_tmpa_tl
}
\ExplSyntaxOff

\begin{document}

\chungeltable{
One, Two, Three, Four
}
{
this is the definition for the One,
this is the definition for the Two,
this is the definition for the Third,
this is the definition for the fourth
}

\end{document}