2

I need to notate this function:

\begin{align*}
  f(x)=\begin{cases} 
    -1,-\pi<x<0 \\
    1,0<x<\pi
  \end{cases}
\end{align*}

How can I get the two conditions to align by the x? Simply putting an ampersand before the x doesn't work (that causes strange space from the lower bound to the x.)

minseong
  • 487

3 Answers3

2

Use alignedat; I also add another form, where adding “for” seems to make the alignment unnecessary.

\documentclass{article}
\usepackage{amsmath}

\begin{document}

\begin{equation*}
\begin{cases}
\begin{alignedat}{2}
-1, & \quad & -\pi & < x < 0   \\
 1, & \quad &    0 & < x < \pi
\end{alignedat}
\end{cases}
\end{equation*}

\begin{equation*}
\begin{cases}
-1, & \text{for $-\pi < x < 0$} \\
 1, & \text{for $0 < x < \pi$}
\end{cases}
\end{equation*}

\end{document}

enter image description here

egreg
  • 1,121,712
0

I propose this, with empheq and alignat*:

\documentclass{article}
\usepackage{empheq}

\begin{document}

\begin{empheq}[left={f(x)=\empheqlbrace}]{alignat*=3}
-1, &\quad & \text{if} &~ & -\pi & < x < 0 \\
 1, & & \text{if}& & 0 & < x < \pi
 \end{empheq}

\end{document} 

enter image description here

Bernard
  • 271,350
0

You can use some \phantom overlapping to achieve the same result:

enter image description here

\documentclass{article}

\usepackage{amsmath}

\begin{document}

\[
  f(x) = \begin{cases} 
              -1, &                     -\pi < x < 0 \\
    \phantom{-}1, & \phantom{-\pi}\llap{$0$} < x < \pi
  \end{cases}
\]

\end{document}
Werner
  • 603,163