你好。这张图片来自我大学的 shhet。我用以下方法制作:
\newcommand{\resii}[2]{%
\begin{center}
\begin{tabular}{|l|c|c|}
\hline
Núm. Objetivo & {#1} & {#2} \\ \hline
0=NL; 1=L & & \\ \hline
\end{tabular}
\end{center}
}
\newcommand{\resiii}[3]{%
\begin{center}
\begin{tabular}{|l|c|c|c|}
\hline
Núm. Objetivo & {#1} & {#2} & {#3} \\ \hline
0=NL; 1=L & & & \\ \hline
\end{tabular}
\end{center}
}
\newcommand{\resiv}[4]{%
\begin{center}
\begin{tabular}{|l|c|c|c|c|}
\hline
Núm. Objetivo & {#1} & {#2} & {#3} & {#4}\\ \hline
0=NL; 1=L & & & & \\ \hline
\end{tabular}
\end{center}
}
\newcommand{\resviii}[8]{%
\begin{center}
\begin{tabular}{|l|c|c|c|c|c|c|c|c|}
\hline
Núm. Objetivo & {#1} & {#2} & {#3} & {#4} & {#5} & {#6} & {#7} & {#8}\\ \hline
0=NL; 1=L & & & & & & & & \\ \hline
\end{tabular}
\end{center}
}
并使用:
\resiv{5}{6}{7}{8}
问题是:如何执行常规命令:
\boxres{"cab1 cab2 ... cabn"} % or with two args:
\boxres{n}{"cab1 cab2 ... cabn"}
处理一盒 n 个盒子:
+--------------+----+----+-----+----+
| OBJ. No. |cab1|cab2| ... |cabn|
+-------+------+----+----+-----+----+
| 0: NL | 1: L | | | | |
+-------+------+----+----+-----+----+
(抱歉,我的英语和 ASCII 艺术格式有关!)
答案1
这是一个解决方案。
\documentclass{article}
\usepackage{array}
\ExplSyntaxOn
\NewDocumentCommand { \boxres } { m }
{
\group_begin:
\seq_set_split:Nnn \l_tmpa_seq { ~ } { #1 }
\begin{tabular}{|l|l|*{20}{c|}}
\hline
\multicolumn{2}{|c|}{OBJ. No.} &
\seq_use:Nnnn \l_tmpa_seq { & } { & } { & } \\
\hline
0: NL & 1: L &
\prg_replicate:nn { \seq_count:N \l_tmpa_seq - 1 } { & } \\
\hline
\end{tabular}
\group_end:
}
\ExplSyntaxOff
\begin{document}
\boxres{cab1 cab2}
\smallskip
\boxres{cab1 cab2 cab3}
\smallskip
\boxres{cab1 cab2 cab3 cab4 cab5}
\end{document}