1

I would like to write a equation which defines quantity f(X) to be a if X>0 and b else. I would like to do so writing f(X)= followed by a curvate bracket and then a if x>0 and b else aligned vertically.

By curvate bracket I mean a \bigg version of {.

2
  • 1
    see the cases environment of the amsmath package. Jun 9, 2016 at 12:53
  • 1
    For example, \documentclass{article} \usepackage{amsmath} \begin{document} \[ f(x) = \begin{cases} a\qquad\text{if } x>0\\b\qquad\text{if } x\le0 \end{cases} \] \end{document}. Additional options are possible if a and b are different widths. Jun 9, 2016 at 12:57

1 Answer 1

2

The cases environment of the amsmath package provides the simplest way to break out a function into different cases. But one can see in the first example that the alignment of the right portion will be affected by the width of what is on the left. Thus, cases supports the use of the alignment tab & to separate and align columns of the case, as shown in the 2nd case.

With the * version of the environment (example 3), which is provided by the mathtools package, the right-hand portion of the case is set as text automatically.

With dcases family of environments, also from the mathtools package, the math is set in \displaystyle automatically (example 4).

As you can see from the comments, there are many environments in the cases family, and one should (myself included) study the documentation to get them all straight.

\documentclass{article}
\usepackage{amsmath,mathtools}
\begin{document}
\[
f(x) = 
\begin{cases}
  a \quad\text{if } x>0\\
  b \quad\text{if } x\le0
\end{cases}
\]
\[
f(x) = 
\begin{cases}
  a & \text{if } x>0\\
  b & \text{if } x\le0
\end{cases}
\]
\[
f(x) = 
\begin{cases*}
 \frac{a}{b}    &  if  $x>0$\\
 b_3  &  for all other situations
\end{cases*}
\]
\[
f(x) = 
\begin{dcases*}
 \frac{a}{b}    &  if  $x>0$\\
 b_3  &  for all other situations
\end{dcases*}
\]
\end{document}

enter image description here

6
  • 1
    Well, amsmath’s cases environment supports the use of & as well. On the other hand, if you load mathtools, you could directly use dcases* and spare the \text{...}.
    – GuM
    Jun 9, 2016 at 13:18
  • 1
    The main difference between cases and dcases is that former sets its material in text-style math mode and the latter typesets its material is display-style math mode. As Gustavo has already pointed out, both environments use & to separate the assertion and conditioning information parts.
    – Mico
    Jun 9, 2016 at 13:21
  • @Mico: You’re right, dcases (with the d) serves no purpose in this case. I’d simply go for cases*.
    – GuM
    Jun 9, 2016 at 13:23
  • @Mico So many environments, so little time. Jun 9, 2016 at 13:30
  • 1
    @StevenB.Segletes: Note that cases* does require mathtools too.
    – GuM
    Jun 9, 2016 at 13:33

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