Latex3:标记列表开头的多列会产生错误

Latex3:标记列表开头的多列会产生错误

我不确定使用标记列表是否是生成表格数据的好方法。无论如何,这是一个奇怪的结果。除了标记列表中的第一个项目是多列的情况外,它在所有其他情况下都运行良好。

\documentclass{article}

\usepackage{xparse}

\ExplSyntaxOn

%Table A
\tl_new:N\g_tabledata_a_tl
\tl_gput_right:Nn\g_tabledata_a_tl{\multicolumn{2}{c}{MyTable} \\}
\tl_gput_right:Nn\g_tabledata_a_tl{My & Table \\}
\NewDocumentCommand{\UseTabledataA}{}{\tl_use:N\g_tabledata_a_tl}

%Table B
\tl_new:N\g_tabledata_b_tl
\tl_gput_right:Nn\g_tabledata_b_tl{My & Table \\}
\tl_gput_right:Nn\g_tabledata_b_tl{\multicolumn{2}{c}{MyTable} \\}
\NewDocumentCommand{\UseTabledataB}{}{\tl_use:N\g_tabledata_b_tl}

\ExplSyntaxOff


\begin{document}
%% Table A. This doesn't work.
\begin{tabular}{cc}
\UseTabledataA
\end{tabular}

\bigskip

%% Table B. This has no problem.
\begin{tabular}{cc}
\UseTabledataB
\end{tabular}

\bigskip

% For reference, this also has no problem
\begin{tabular}{cc}
\multicolumn{2}{c}{MyTable} \\
My & Table \\
\end{tabular}
\end{document}

错误信息是:

放错了 \omit.\multispan ->\omit\@multispan \UseTabledataA

我知道多列必须是单元格中的第一项。也许这与此有关?

答案1

细胞内容必须扩张要查看\omit形成跨越单元格,您需要

\documentclass{article}

\usepackage{xparse}

\ExplSyntaxOn

%Table A
\tl_new:N\g_tabledata_a_tl
\tl_gput_right:Nn\g_tabledata_a_tl{\multicolumn{2}{c}{MyTable} \\}
\tl_gput_right:Nn\g_tabledata_a_tl{My & Table \\}
\NewExpandableDocumentCommand{\UseTabledataA}{}{\tl_use:N\g_tabledata_a_tl}

%Table B
\tl_new:N\g_tabledata_b_tl
\tl_gput_right:Nn\g_tabledata_b_tl{My & Table \\}
\tl_gput_right:Nn\g_tabledata_b_tl{\multicolumn{2}{c}{MyTable} \\}
\NewDocumentCommand{\UseTabledataB}{}{\tl_use:N\g_tabledata_b_tl}

\ExplSyntaxOff


\begin{document}
%% Table A. This doesn't work.
\begin{tabular}{cc}
\UseTabledataA
\end{tabular}

\bigskip

%% Table B. This has no problem.
\begin{tabular}{cc}
\UseTabledataB
\end{tabular}

\bigskip

% For reference, this also has no problem
\begin{tabular}{cc}
\multicolumn{2}{c}{MyTable} \\
My & Table \\
\end{tabular}
\end{document}

相关内容