# How to align equations cases environment

The following code:

\documentclass{article}
\usepackage{amsmath}
\begin{document}
$\begin{cases} Af &=g \quad \text{if} \ c,\\ f&=0 \quad \text{if} \ d. \end{cases}$
\end{document}


gives

How to align the two f's vertically (so that they are both in the same distance from the '=' sign)?

• I don't see the reason for \quad there. In the second line, write \phantom{A}f to get the fs aligned. Mar 23 '16 at 9:02
• @Manuel Yes, that is what I wanted. But is there not any other solution, like specifying the alignment requirements in the options of 'cases'? Mar 23 '16 at 9:05
• Ah, I see, in {cases}, the & is there to separate columns, not before the equal. Mar 23 '16 at 9:06
• @Manuel Sorry, I don't get what you mean and how it can help me. Mar 23 '16 at 9:11
• You are not supposed to write &= inside a {cases} environment. Mar 23 '16 at 10:22

Use aligned instead of cases. If you wonder, why there is \! after \left\{, see Why is there a \, space at the beginning of the “aligned” environment?.

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\left\{\!\begin{aligned} Af &=g && \text{if} \ c,\\ f &=0 && \text{if} \ d. \end{aligned}\right.
\end{document}


\documentclass{scrartcl}
\usepackage{mathtools}
\begin{document}
$\begin{cases} Af=g & \text{if} \ c, \\ \phantom{A}f = 0 & \text{if} \ d. \end{cases}$
\end{document}


Altough I tend to prefer

\begin{cases*}
Af=g & if $c$, \\
\phantom{A}f = 0 & if $d$.
\end{cases*}