\int_step_inline:nn 不能被完全展开,而且 expand 选项只会展开一次,只能使用类似 \int_step_inline:nn {} { \tl_put_right:Nn ... } 的方式将内容存入宏中,然后再在 tblr 中展开这个宏。
\documentclass{ctexart}
\usepackage{tabularray}
\ExplSyntaxOn
% \tl_new:N \l__my_choice_colspec_tl % colspec 选项可要可不要
\tl_new:N \l__my_choice_content_tl
\NewDocumentCommand \choiceTable { +O{} O{1} m m } % tblr options, first num, last num, ...
{
% \tl_set:Nx \l__my_choice_colspec_tl { \prg_replicate:nn { #3-#2+2 } { l } } % colspec 选项
\tl_clear:N \l__my_choice_content_tl
\tl_put_right:Nn \l__my_choice_content_tl { 题号 }
\int_step_inline:nnnn {#2} { 1 } {#3}
{ \tl_put_right:Nn \l__my_choice_content_tl { & ##1 } }
\tl_put_right:Nn \l__my_choice_content_tl { \\ 答案 }
\tl_put_right:Nx \l__my_choice_content_tl
{ \prg_replicate:nn { #3 - #2 } { & } } % 第二行的 & & & ...
% \tl_put_right:Nn \l__my_choice_content_tl { \\ } % 最后一个 \\ 可要可不要
\begin{tblr} [ expand = \l__my_choice_content_tl ] {#1}
\l__my_choice_content_tl
\end{tblr}
}
\ExplSyntaxOff
\begin{document}
\choiceTable[hlines,vlines]{5}{}
\choiceTable[hlines,vlines][6]{10}{}
\end{document}
当然,这个实现并不能自动换行,但是也不难实现,只要在适当位置插入 \\ 等内容即可。







问 tabularray包可以实现可变列数的表格吗?