The cases environment in latex

The cases environment defined by the amsmath package sets each case to be inline math style. This will look ugly when the formulas in the cases are complicated, such as fractions or integrals. Consider the following sample code:

\usepackage{amsmath}
\[
f(x)=
\begin{cases}
\frac{1}{2(x-1)}, & x>1 \\
\frac{\Gamma(x)}{2^{x-1}}, & 0<x<1
\end{cases}
\]

The result looks like this:

The solution is to use the dcases environment provided by the mathtools package instead. The prefix `d’ means `display’. It will set the cases in displayed math style (exactly the same as \frac versus \dfrac). So if we write the following code

\usepackage{amsmath,mathtools}
\[
f(x)=
\begin{dcases}
\frac{1}{2(x-1)}, & x>1 \\
\frac{\Gamma(x)}{2^{x-1}}, & 0<x<1
\end{dcases}
\]

then we will see the result which looks like this:

Advertisements

2 Responses to “The cases environment in latex”


  1. 1 Sotiris December 1, 2011 at 3:02 am

    you can also just use dfracs and at the end of the first line use \\[3ex] instead of \\

    • 2 Jie December 1, 2011 at 12:51 pm

      Yes you are right. But there are two reasons why I don’t. First I just don’t like manually controlling the line spacing. Second, this only works for fractions, but not integrals or other complicated formulas. The point is that the cases environment set the cases in inline math style, which does not look good sometimes. To make them all changed to displayed style, you might need to add \displayedmath in each case. In that case, why not just use the mathtools package for simplicity?


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




Categories

Blog Stats

  • 244,135 hits

%d bloggers like this: