Trying to compile the seemingly straightforward code
\documentclass{standalone}
\usepackage{booktabs}
\usepackage{array}
\usepackage{xparse}
\usepackage{tabu}
\NewDocumentCommand{\TblHdr}{O{1} m}{
\multicolumn{#1}{c}{\bfseries #2}
}
\begin{document}
\begin{tabu}{r*{4}{c}}
\toprule
\TblHdr{1} & \TblHdr{2} & \TblHdr{3} & \TblHdr{4} \\
\midrule
1 & 2 & 3 & 4 \\
A & B & C & D \\
W & X & Y & Z \\
\bottomrule
\end{tabu}
\end{document}
gives me the following error:
! Misplaced \omit.
\multispan ->\omit
\@multispan
l.20 \end{tabu}
?
I have searched the site, but none of the other questions/answers appeared to have helped. Furthermore, if at all possible, I'd like to understand what exactly is going on here. As I said, the code seems pretty straightforward.
\multicolumncannot be used with\NewDocumentCommand. I think this has already appeared. – egreg Mar 19 '17 at 20:13