Multicolumn within a newcommand error
\multicolumn
must be the first thing in a table cell and a command with a star variant defined in the usual way hides \multicolumn
after some unexpandable token. Without packages you can do in the following way:
\documentclass{article}
\newcommand{\topics}[1]{%
\if*\detokenize{#1}%
&%
\else
\multicolumn{2}{|p{2in}|}{#1}%
\fi
}
\begin{document}
\begin{tabular}{|p{1in}p{1in}|}
\topics{stuff} \\
\topics* \\
\topics{some more stuff} \\
\topics* \\
\topics*
\end{tabular}
\end{document}
This solution is built on the requirement suggested by Heiko in ! Misplaced \omit
error.
etextools
provides fully-expandable conditioning commands to allow \multicolumn
to be considered as "the first element in the cell". This is not currently the case in your example, since \@ifstar
is not fully expandable, while \FE@ifstar
is a F
ully E
xpandable version:
\documentclass{article}
\usepackage{etextools}% http://ctan.org/pkg/etextools
\makeatletter
\newcommand{\topics}[1]{%
\FE@ifstar{#1}
{test & test}% starred
{\multicolumn{2}{|p{2in}|}{#1}\@gobble}}% non-starred
\makeatother
\begin{document}
\begin{tabular}{|p{1in}p{1in}|}
\topics{stuff} \\
\topics* \\
\topics{some more stuff} \\
\topics* \\
\topics*
\end{tabular}
\end{document}