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

  • Welcome to TeX.SX! What should the optional argument do in that example? – leandriis May 2 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 at 19:28
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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.