Misplaced \omit. \multispan with \newcommand
Tabular material is really picky about what is allowed to go "before" a line. In particular, it has to be fully expandable.
Hence, even the assignment which \ingredient
needs to do to check for its optional argument is enough to start the line, and then \multicolumn
is no longer allowed to appear.
The easiest way to remedy this is to make the first argument of \ingredient
mandatory:
\documentclass{scrartcl}
\newcommand{\ingredient}[3]{
#1 #2 & #3 \\
}
\begin{document}
\begin{tabular}{r|l}
\ingredient{\multicolumn{2}{l}{Head} \\}{test1}{test2}
\ingredient{test3}{test4}{test5}
\ingredient{}{test6}{test7}
\end{tabular}
\end{document}
You can retain your original syntax and have a single macro with an optional parameter if you use \DeclareExpandableDocumentCommand
from the the xparse
package.
Code:
\documentclass{scrartcl}
\usepackage{xparse}
\DeclareExpandableDocumentCommand{\ingredient}{O{} m m}{%
#1 #2 & #3 \\%
}%
\begin{document}
\begin{tabular}{r|l}
\ingredient[\multicolumn{2}{l}{Head} \\]{test1}{test2}
\ingredient[test3]{test4}{test5}
\ingredient{test6}{test7}
\end{tabular}
\end{document}