3

In the following example, I was wondering how to align the equation cases at the equal/in signs, in addition to the current alignment at "for".

None of the solutions here seems to work.

Thanks.

\documentclass{article} 
\usepackage{amsmath}
\begin{document}
\begin{equation*}
    f(x) = \begin{cases}
        -x &\text{for every} \enspace x \in [-1, 0), \\
        \hphantom{-}d &\text{for} \enspace x = 0, \\
        2-x &\text{for every} \enspace x \in (0,1].
    \end{cases}
\end{equation*}
\end{document}

enter image description here

2 Answers 2

3

Since you're using similar characters (and therefore widths), using a \phantom would align the content the way you want it to.

enter image description here

\documentclass{article} 

\usepackage{amsmath}

\begin{document}

Original:
\[
  f(x) = \begin{cases}
    -x            &\text{for every} \enspace x \in [-1, 0), \\
    \hphantom{-}d &\text{for} \enspace x = 0,               \\
    2 - x         &\text{for every} \enspace x \in (0,1].
  \end{cases}
\]

With \verb|\phantom|:
\[
  f(x) = \begin{cases}
    -x            & \text{for every }           x \in [-1, 0), \\
    \hphantom{-}d & \text{for \phantom{every} } x = 0,         \\
    2 - x         & \text{for every }           x \in (0,1].
  \end{cases}
\]

\end{document}

More generally you can use aligned and friends. For example, in this case, you want 3 alignments, really. One for the case, second for the condition and then a third for the range alignment. For this, use alignedat.

I've adjusted the alignedat solution/example to emphasize the alignment when having different conditions.

enter image description here

\documentclass{article} 

\usepackage{amsmath}

\begin{document}

Original:
\[
  f(x) = \begin{cases}
    -x            &\text{for every} \enspace x \in [-1, 0), \\
    \hphantom{-}d &\text{for} \enspace x = 0,               \\
    2 - x         &\text{for every} \enspace x \in (0,1].
  \end{cases}
\]

With \verb|\phantom|:
\[
  f(x) = \begin{cases}
    -x            & \text{for every }           x \in [-1, 0), \\
    \hphantom{-}d & \text{for \phantom{every} } x = 0,         \\
    2 - x         & \text{for every }           x \in (0,1].
  \end{cases}
\]

With \verb|alignedat|:
\[
  f(x) = \begin{cases}
    \begin{alignedat}{3}
      &{-}x          & \quad & \text{for every } & abc &\in [-1, 0), \\
      &\hphantom{-}d &       & \text{for }       &   d &= 0,         \\
      &2 - x         &       & \text{for every } &  ef &\in (0,1].
    \end{alignedat}
  \end{cases}
\]

\end{document}
2
  • Werner: I was wondering why the discussion that we had here in the comment section about your solution was removed.
    – AEW
    Jun 26 at 18:31
  • @AEW: I deleted the comments after the necessary updates were implemented in the answer. Where there anything in particular you're still questioning?
    – Werner
    Jun 27 at 3:44
2

Isn't the "every" qualifier implied in the conditions stated in rows 1 and 3? I don't think you need it.

enter image description here

\documentclass{article} 
\usepackage{amsmath}
\begin{document}
\begin{equation*}
    f(x) = 
    \begin{cases}
        -x            & \text{if $x \in [-1, 0)$}, \\
        \hphantom{-}d & \text{if $x = 0$}, \\
        2-x           & \text{if $x \in (0,1]$}.
    \end{cases}
\end{equation*}
\end{document}
1
  • Yes, but I still need to do that for the purpose of other similar situations, without \phantom{every}, typically by including \begin{aligned} ... \end{aligned}. Thanks.
    – AEW
    Jun 8 at 20:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .