0

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):

  • 3
    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
3

Updated standaloneclass and aligned environment

\documentclass[preview]{standalone}
\usepackage{amsmath,mathtools}
\begin{document}
\begin{equation*}
| x | =
\left\{
 \begin{aligned}
    &a\quad\text{if \dots}\\
    -&a\quad\text{if \dots}
\end{aligned}
 \right.
\end{equation*}
\end{document}

enter image description here

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

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

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.