# How to align a variable whose sign is absent with a variable whose sign is present while both are inside \begin{cases}\end{cases}?

I can't seem to align variables properly since one of them leaves its sign behind on alignment.

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

% NO ALIGNMENT
$\begin{gathered} |x|= \begin{cases} a\medspace{}\text{if \dots}\\ -a\medspace{}\text{if \dots} \end{cases} \end{gathered}$

% IMPROPER ALIGNMENT
$\begin{gathered} |x|= \begin{cases} &a\medspace{}\text{if \dots}\\ -&a\medspace{}\text{if \dots} \end{cases} \end{gathered}$

\end{document}

I would like to avoid using \phantom as well as complicated macros.

This is what I'm looking for (from a book):

• I don't understand why there is a ban on \phantom here? It seems like an ideal place to use it. All other options will just require more work-around and more code... – Werner Feb 17 at 5:59

Updated standaloneclass and aligned environment

\documentclass[preview]{standalone}
\usepackage{amsmath,mathtools}
\begin{document}
\begin{equation*}
| x | =
\left\{
\begin{aligned}
\end{aligned}
\right.
\end{equation*}
\end{document}

• @bp2017 answer updated – Hafid Boukhoulda Feb 17 at 3:43
• @bp2017 answer updated using standalone class and aligned environment – Hafid Boukhoulda Feb 17 at 6:40

Since you banned \phantom ....

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

$|x|=\left\{ \begin{array}{rl} a &\text{if \dots}\\ - a &\text{if \dots} \end{array} \right.$

\end{document}

Notes:

1. `standalone' is not for this purpose

2. use [ ] for display math (or the equation environment if numbered)

3. There is nothing wrong with \phantom

• Why? Is this homework? – JPi Feb 17 at 12:23