168

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?

Michael
  • 125
Nikhil
  • 2,375
  • 5
  • 19
  • 14
  • 2
    See also cases* environment from mathtools (that interprets the second column as text): https://tex.stackexchange.com/a/262081/250119 – user202729 Nov 07 '21 at 03:36

5 Answers5

223

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

AboAmmar
  • 46,352
  • 4
  • 58
  • 127
42

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

AboAmmar
  • 46,352
  • 4
  • 58
  • 127
30
x = \begin{cases}
  0, & \text{if } a = 1, \\
  1, & \text{otherwise}.
\end{cases}

amsmath is needed for \text.

David Carlisle
  • 757,742
Leo Liu
  • 77,365
  • 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 08 '21 at 02:09
5

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

2

Here is a way to manually control the size of brace, if cases or \left\{ doesn't provide suitable brace size you want.

\begin{math}
\biggl\{
    \begin{array}{l}
        statement1\\
        statement2
    \end{array}
\end{math}

You can choose among \bigl\{ \Bigl\{ \biggl\{ \Biggl\{ to adjust brace size from the smallest to the largest. Different brace sizes using different methods

From left to right: cases \left\{ biggl\{ Bigl\{

William
  • 21