我正在使用逗号分隔列表的输入来构建表格。(请参阅我之前的问题)。现在,我想要一个带有两个参数的命令(每个名称一个参数,每个定义一个参数):
例如:
\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}
以下将针对 中给出的第一个参数的每次出现打印第二个参数中存在的所有项目 \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
我该如何修复这个问题,以便它在第一列(名称)中打印第一个参数的每个项目,在第二列(说明)中打印第二个参数的每个项目?
答案1
您必须从两个列表中一次选择一个项目:
\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}