5

If you are using a command to append a multiline to a tabular, it will stop working if the command has optional arguments. It will work without them:

\documentclass{standalone}
\newcommand{\mwe}[2][1]{ % remove [1]
    \multicolumn{2}{l}{text}
}
\begin{document}
    \begin{tabular}{ll}
        \mwe[1]{1} % [1]->{1}
    \end{tabular}
\end{document}  

(Minimal working example, works when changed according to comments)

Error:

Misplaced \omit

2
  • Welcome to TeX.SX! What should the optional argument do in that example?
    – leandriis
    May 2, 2020 at 19:21
  • I wanted to use the command to append a Quote to the table (+other normal table stuff) If it would be too long for one row, i wanted to use the optional argument to be able to split the Quote over 2 lines. Like ------------------ "this is a short Quote" 1 2 3 ------------------ "This Quote is too long for one row" 1 2 3
    – Philip G.
    May 2, 2020 at 19:28

1 Answer 1

5

This is a known problem: \multicolumn has to be the first object in a cell (after expanding macros), but the command with optional argument places something before it.

Use xparse.

\documentclass{standalone}
\usepackage{xparse}

\NewExpandableDocumentCommand{\mwe}{O{1}m}{%
    \multicolumn{2}{l}{text}%
}

\begin{document}
    \begin{tabular}{ll}
        \mwe[1]{1} % [1]->{1}
    \end{tabular}
\end{document}

So long as the list of arguments ends with m (a mandatory argument), the command is fully expandable.

You must log in to answer this question.

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