145

How do I produce a conditional expression with large brackets?

For example:

X = 0 if a=1, 1 otherwise, with a large left bracket and specifying each condition in a line?

1

4 Answers 4

197

The cases environment from amsmath does the trick.

\documentclass{article}
\usepackage{amsmath}

\begin{document}
  \begin{equation}
    X=
    \begin{cases}
      0, & \text{if}\ a=1 \\
      1, & \text{otherwise}
    \end{cases}
  \end{equation}
\end{document}

Result

1
  • Should there be space in between a and = ; = and 1?
    – alper
    Feb 11 at 11:21
36

Another method, which is especially helpful if one needs to have more control over the items alignment, is the array construct.

\documentclass{article}
\usepackage{amsmath}    
\begin{document}

\begin{equation}
  X=\left\{
  \begin{array}{@{}ll@{}}
    0, & \text{if}\ a=1 \\
    1, & \text{otherwise}
  \end{array}\right.
\end{equation} 

\end{document}

enter image description here

Instead of ll, one may choose cc, rr, rl, etc. Besides, all the array capabilities can be applied here (\arraycolsep, \arraystretch, \extrarowheight by loading the array package, etc).

One more alternative could be using the aligned environment and adding the pseudo-parenthesis ., which can be used to terminate an opening parenthesis {.

\documentclass{article}
\usepackage{amsmath}    
\begin{document}

\begin{equation}
  X = \left \{
  \begin{aligned}
    &0, && \text{if}\ a=1 \\
    &1, && \text{otherwise}
  \end{aligned} \right.
\end{equation} 

\end{document}

enter image description here

2
  • should we put . after otherwise?
    – alper
    Feb 11 at 11:27
  • In most cases, yes we should, based on the context.
    – AboAmmar
    Feb 11 at 18:07
26
x = \begin{cases}
  0, & \text{if } a = 1, \\
  1, & \text{otherwise}.
\end{cases}

amsmath is needed for \text.

1
  • the & characters makes the {cases} environment break for me in equations written in \begin{align*} environments using amsmath - so I put spacing in with \qquad and similar
    – tom
    Nov 8, 2021 at 2:09
4

Iverson bracket can also be used: $x=[a \neq 1]$.

1
  • Knuth is a fan of Iverson notation, using it heavily in Concrete Mathematics among other publications. BTW, here to match the original question, I think you mean $x = [a \neq 1]$ :-) Jan 16, 2017 at 17:30

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.