A piecewise definition is a brace plus two columns — a value and a condition — not a matrix with a big brace drawn on the left. The cases environment supplies the brace and keeps both columns left-aligned; everything else is the ordinary row syntax from Align. Conditions that talk about sets need Set Notation, and a tall branch brings back the sizing problem from Fractions.
Which one to use
cases& \text{if } x>0\text{otherwise}\text, not maths italics.\mathbf{1}_{\{x>0\}}cases\dfracThe commands
f(x)=\begin{cases} x & x \ge 0 \\ -x & x < 0 \end{cases}
\operatorname{sgn}(x)=\begin{cases} 1 & x > 0 \\ 0 & x = 0 \\ -1 & x < 0 \end{cases}
\text{}, otherwise they print as a product of italic letters. \begin{cases} 1 & \text{if } x \in A \\ 0 & \text{otherwise} \end{cases}
y=\begin{cases} t^2, & 0 \le t < 1 \\ 2t-1, & t \ge 1 \end{cases}
\mathbf{1}_A(x)=\begin{cases} 1 & x \in A \\ 0 & x \notin A \end{cases}
g=\begin{cases} x^2+1 & 0 \le x < 3 \\ 7 & x \ge 3 \end{cases}
\frac{1}{1+e^{-x}}
\begin{cases} \begin{aligned} x &= 1 \\ y &= 2 \end{aligned} & t > 0 \end{cases}
Worked examples
A step function
H(x)=\begin{cases} 0 & x < 0 \\ 1 & x \ge 0 \end{cases}
The Heaviside function, and the reason the condition column matters: both rows share the same variable name.
Clamping to a range
f(x)=\begin{cases} 0 & x < 0 \\ x & 0 \le x \le 1 \\ 1 & x > 1 \end{cases}
Three branches covering the middle band. Conditions overlap at endpoints only where the value agrees there.
Modulus as a definition
|x|=\begin{cases} x & x \ge 0 \\ -x & x < 0 \end{cases}
The bar notation and its cases expansion side by side; transcribing from an image usually gives you one and asks for the other.
A recursive-looking branch
a_n=\begin{cases} 1 & n = 0 \\ 2a_{n-1} & n > 0 \end{cases}
Subscripts inside the value column behave exactly as they do outside cases.
Common mistakes
- Leaving out the
&. Two tokens with no separator print as one multiplication in the value column and no condition ever appears. - Writing
\text{if }x>0without the trailing space inside\text{}, which glues the word to the inequality. - Using
<=or>=. Those are programming operators; LaTeX wants\leand\ge, and the ASCII form silently prints an unexpected symbol. - Trying to add your own
\left\{in front ofcases. The environment already supplies the brace, so you get two.
Questions about this notation
Does cases need amsmath?
How do I add a second condition on the same line?
\le x < 3 covers a range in a single column. For genuinely unrelated conditions, split them with a comma inside \text{} rather than adding another ampersand, because a third column will shift everything.Can the value column contain a fraction?
\tfrac often reads better there.How do I write an indicator function, or keep a piecewise definition at full size?
cases is set in text style, so fractions inside it shrink. dcases from the mathtools package is the same environment at display style. For an indicator function the two usual forms are \mathbf{1}_{A}(x) and \mathbb{1}_{A}(x); the plain digit 1 is also standard and never depends on a font providing a blackboard-bold one.Keep reading
Three ways into the same idea: the notation itself, the lesson that teaches it, and an article that applies it.