Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

In one big align environment, I want to put some cases environments. I would like the alignment of the cases environments to be the same. For example, if I write:

\begin{align}
f(x) &= 
  \begin{cases}
    x & \text{if } x\geq 0,\\
    -x & \text{if } x <0,
  \end{cases}\\
g(x) &=
  \begin{cases}
    \sqrt{x} & \text{if } x \geq 0,\\
    -\sqrt{-x} & \text{if } x < 0.
  \end{cases}
\end{align}

then the equation looks ugly because the two cases environment are aligned at different points. Is there a way to force the alignment point of the two environment to be the same?

share|improve this question
    
See also Aligning the right parts in multiple \begin{cases} (possible duplicate), but here you have the better answers. –  Hendrik Vogt Feb 3 '13 at 8:09
    
I searched for it, but I did not find anything. Thanks! –  antonio Feb 4 '13 at 17:12
add comment

2 Answers 2

You could also use a \hphantom{} to add the appropriate amount of horizontal space:

enter image description here

Code:

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align}
f(x) &= 
  \begin{cases}
    x\hphantom{-\sqrt{-}} & \text{if } x\geq 0,\\
    -x & \text{if } x <0,
  \end{cases}\\
g(x) &=
  \begin{cases}
    \sqrt{x} & \text{if } x \geq 0,\\
    -\sqrt{-x} & \text{if } x < 0.
  \end{cases}
\end{align}
\end{document}
share|improve this answer
    
I was hoping in something that does not require some sort of manual spacing, that I could also use in more complicated examples. Thank you anyway! –  antonio Feb 4 '13 at 17:16
add comment

You can enclose one of the entries in the first cases environment in a box whose width is that of the longest of the second cases environment.

\newlength{\temp}
\settowidth{\temp}{$-\sqrt{-x}$}
\begin{align}
f(x) &= 
  \begin{cases}
    \makebox[\temp][l]{$x$} & \text{if } x\geq 0,\\
    -x & \text{if } x <0,
  \end{cases}\\
g(x) &=
  \begin{cases}
    \sqrt{x} & \text{if } x \geq 0,\\
    -\sqrt{-x} & \text{if } x < 0.
  \end{cases}
\end{align}

enter image description here

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.