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

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

  • Why are you using the equation environment instead of align? Please can you have a look at my follow-up question – theonlygusti Sep 21 '17 at 13:08
  • @theonlygusti For a single equation it's better to use equation; align is for multiline displays (cases isn't). – egreg Sep 21 '17 at 13:12
  • what about the equation environment vs $$? – theonlygusti Sep 21 '17 at 13:22
  • @theonlygusti $$ should never be used in LaTeX. See Why is \[ … \] preferable to $$? – egreg Sep 21 '17 at 13:41
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

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}

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.