我正在使用\multicolumn
以下代码。但它没有产生正确的输出,请参阅附件的输出。
哪里有问题?
\documentclass{article}
\usepackage{etextools}% for entry
\usepackage{longtable}
\usepackage{xparse}
\usepackage{xstring}
\usepackage{listofitems}
\NewDocumentCommand\separateswarbol{m}{\StrBefore{#1}{)}[\swars] \StrBetween{#1}{[}{]}[\bols]}
\begin{document}
\separateswarbol{x,y,z,w)[a,b,c,d]}
\readlist\bollist{\bols}%
\readlist\swarlist{\swars}%
\newcounter{swarstringlen}%
\newcounter{actualswarstringlen}%
\newcounter{bolstringlen}%
\newcounter{spos}%
\newcounter{bpos}%
\StrCount{\swars}{,}[\swarlen]%
\StrCount{\bols}{,}[\bollen]%
\setcounter{swarstringlen}{\swarlen}%
\setcounter{actualswarstringlen}{\swarlen}%
\addtocounter{actualswarstringlen}{1}%
\addtocounter{swarstringlen}{2}%
\setcounter{bolstringlen}{\bollen}%
\stepcounter{bolstringlen}%
\stepcounter{bolstringlen}%
\setcounter{spos}{1}%
\setcounter{bpos}{1}%
\begin{longtable}{*{16}c}%
\whileboolexpr%
{test{\ifnumcomp{\value{spos}}{<}{\value{swarstringlen}}}}%
{\ifnum\value{spos}=\value{actualswarstringlen}\uppercase{&}\multicolumn{1}{c|}{\swarlist[\thespos]}\addtocounter{spos}{1}\else\uppercase{&}\multicolumn{1}{c}{\swarlist[\thespos]}\stepcounter{spos}\fi%
}\\
\whileboolexpr%
{test {\ifnumcomp{\value{bpos}}{<}{\value{bolstringlen}}}}%
{\ifnum\value{bpos}=\value{actualswarstringlen}%
\uppercase{&}\multicolumn{1}{c|}{\bollist[\thebpos]}\addtocounter{bpos}{1} %
\else \uppercase{&}\multicolumn{1}{c}{\bollist[\thebpos]}\stepcounter{bpos}\fi%
}
\end{longtable}
\end{document}