[Tex/LaTex] Problem compiling cases environment


I am trying to compile a simple cases example, but I'm having trouble with the tabular separator &. Here's my code:

    f(x) = 
        x + 1 & \mbox{blabla} \\
        x & \mbox{otherwise}

I am getting the following errors:

Misplaced alignment tab character &. x + 1 &

Misplaced alignment tab character &. x &

What could be wrong?

Best Answer

Short answer

The cases environment requires the amsmath package:


Long answer

For historical reasons, LaTeX defines a \cases macro: on page 232 of Lamport's manual one reads

Most Plain TeX commands can be used in LaTeX, but only with care.

and \cases is indeed a Plain TeX command which has quite a different syntax than the cases environment. It would be possible to use it without loading amsmath, but the features of this package are much better than the Plain TeX commands: more flexible and with a uniform syntax.

By the way, here's how one could input the equation with this method:

f(x) = 
  x + 1 & blabla \cr
  x & otherwise \cr

It's evident that the syntax is foreign to LaTeX: the second column is typeset in text mode and not math mode and the lines must be terminated by \cr. Most important, the alignment must go between braces: this is the main cause of the error.

Don't use it and stick to \usepackage{amsmath}.

Related Question