I want to write a command that will produce a table, but can also add one multicolumn with an optional argument's contents in it. I tried to do this using ifthenelse to check if the optional argument is empty, but something about having the brackets around multicolumn gives me a mispaced \omit error, and causes the column to be misaligned.
Here is what the command would look like:
\newcommand{\namecol}[1][]{
\begin{table}[h!]
\begin{tabular}{|rlrl|}
\ifthenelse{\equal{#1}{}}{}{%
\multicolumn{4}{|l|}{#1} \\
}
a & b & c & d \\
e & f & g & h \\
\end{tabular}
\end{table}
}
and below are the results of calling \namecol and \namecol[x], respectively:



\namecol[zz]for example. – David Carlisle Jan 03 '21 at 12:46\ifx\relax#1not\ifx#1\relax) – David Carlisle Jan 03 '21 at 14:16