3

I would like to completely understand all the differences between using the amsmath environment cases and using the array environment to write functions with cases.

Here is my current understanding after reading other questions in the forum:

  • array comes with padding on the left and the right. It can be suppressed using {@{}ll@{}} as explained in this related question.
  • array creates vertical spacing issues that I don't fully understand. See this related question.
  • Both array and cases allow changing the space between lines using, for instance, \\[2ex].
  • It is much easier to change the alignment of columns with array than with cases.
  • The left brace from cases seems to be taller than the left brace from array. But I don't understand why.
  • Using cases is semantically more appropriate.
  • cases requires loading amsmath

Overall, it seems like the default version of cases is better, but array is more customizable.

Are there other differences that I am missing? Is there an aspect of functions with cases that can be formatted using one of the environments but not the other one?

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\[
    |x| =
        \begin{cases}
            x & \text{if}\ x\geq 0\\
            -x & \text{if}\ x<0\\
        \end{cases}.
\]
\end{document}

function generated with cases

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\[
    |x| = 
        \left\{\begin{array}{ll}
            x & \text{if}\ x\geq 0\\
            -x & \text{if}\ x<0\\
        \end{array}\right..
\]
\end{document}

function generated with array

What I really want to know is which of the two environments is better and why. I have been using array for years, but I am considering switching to cases.

0
8

The code for cases in amsmath is just

\renewenvironment{cases}{%
  \matrix@check\cases\env@cases
}{%
  \endarray\right.%
}
\def\env@cases{%
  \let\@ifnextchar\new@ifnextchar
  \left\lbrace
  \def\arraystretch{1.2}%
  \array{@{}l@{\quad}l@{}}%
}

so it is array with a column specification of {@{}l@{\quad}l@{}} and arraystretch of 1.2

3
  • Thank you, this is very useful! – brunosalcedo Mar 21 '20 at 15:01
  • 1
    You might mention cases* from mathtools, which allows r/l adjustments. And, although not used in a "cases" situation, array also allows c to center a column. (May as well be complete.) – barbara beeton Mar 21 '20 at 22:02
  • You can use \hfil to center a column in cases if desired: \begin{cases} \hfil x & \text{if } x\geq 0\\ -x & \text{if } x<0. \end{cases}. More manipulation is possible with arrays, but when copyediting authors' tex files, I almost always change cases to the cases environment. The more "opportunity" authors are given to adjust spacing, the more likely it is that infelicities will be introduced. (In a similar vein, \text{if } is preferable to \text{if}\ or \text{if}\; etc.) In my opinion, cases should be the default choice, unless you need to do something complicated. – Fintan May 5 '20 at 16:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.