3

I have a need to format the first row of my table differently from the rest, and read this answer, which was very useful. So I tried to encapsulate the \multicolumn{1}{c}{#2} into a macro:

\newcommand\fr[1]{\multicolumn{1}{c}{#2}}

which also worked fine. Never happy, I decided to try to make the column style an optional parameter, so wrote

\newcommand\bad[2][c]{\multicolumn{1}{c}{#2}}

Using this macro results in the error

./foo.tex:17: Misplaced \omit.
\multispan ->\omit
               \@multispan
l.17     \bad{1} & \bad{1} & \bad{1}
                                 \\
I expect to see \omit only after tab marks or the \cr of
an alignment. Proceed, and I'll ignore this case.

./foo.tex:17: Incompatible list can't be unboxed.
\@arstrut ->\unhcopy \@arstrutbox

l.17     \bad{1} & \bad{1} & \bad{1}
                                 \\
Sorry, Pandora. (You sneaky devil.)
I refuse to unbox an \hbox in vertical mode or vice versa.
And I can't open any boxes in math mode.

./foo.tex:17: You can't use `macro parameter character #' in restricted horizontal mode.
\@preamble ...ol@sep \hfil $\ignorespaces \@sharp
                                              \unskip \relax $\hfil \hsk...
l.17     \bad{1} & \bad{1} & \bad{1}
                                 \

Here is a small (non-)working example:

\documentclass{book}
\usepackage{amsmath}
\usepackage{array}

\newcommand{\fr}[1]{\multicolumn{1}{c}{#1}}
\newcommand{\bad}[2][c]{\multicolumn{1}{#1}{#2}}

\begin{document}

\begin{equation*}
  \begin{array}{r r r}
    \fr{1} & \fr{1} & \fr{1} \\
    2.4 & 2.5 & 2.6 \\
    25.123 & 100.457 & -3.488
  \end{array}
  \begin{array}{r r r}
    \bad{1} & \bad{1} & \bad{1} \\
    2.4 & 2.5 & 2.6 \\
    25.123 & 100.457 & -3.488
  \end{array}
\end{equation*}
\end{document}

I'm sure this is something really silly, but I don't know enough to figure out what.

David Carlisle
  • 757,742
rogerl
  • 3,583
  • 5
  • 29
  • 39
  • @cfr has pointed to the correct solution. Whenever you're using optional arguments, you're not working in a fully expandable context, which is what you need with tabular environment parameters and such. – A.Ellett Dec 13 '13 at 04:05

0 Answers0