2

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
        \endhead
        \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)?

Chüngel
  • 189

1 Answers1

2

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
        \endhead
        \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}

enter image description here

egreg
  • 1,121,712