2

When I try to insert a \multicolumn with a macro created using xparse's \NewDocumentCommand, I get a Misplaced \omit error. When I define the "same" command using \def, every thing works fine.

How come? Can I work around this somehow?

\documentclass{article}

\usepackage{xparse}

% This definition does not work.
\NewDocumentCommand\foo{}{%
 \multicolumn{1}{c}{asdf}%
}

% This one does.
%\def\foo{%
% \multicolumn{1}{c}{asdf}%
%}

\begin{document}

\begin{tabular}{ c }
  \foo
\end{tabular}

\end{document}
1
  • \NewDocumentCommand defines the macro as robust, you can use \NewExpandableDocumentCommand instead.
    – Skillmon
    Dec 5, 2019 at 14:20

1 Answer 1

4

\multicolumn should be the first thing in a cell (after macro expansion). With \NewDocumentCommand this is not possible.

You need

\NewExpandableDocumentCommand{\foo}{}{\multicolumn{1}{c}{asdf}}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .