[Tex/LaTex] Aligning conditions in cases environment

casesvertical alignment

I have a piecewise function with three "parts." I would like to have all three conditions aligned at the variable x. How do I achieve that? Here is the code I have so far:

\[
f(x) = \begin{cases} 
                mx^2 +nx +1, & x \le -1 \\ 
                2m e^{|x|-1} + \sin \pi x - 3n, & -1 < x < 1 \\ 
                3x^2 - (m+n)x, & x \ge 1 
           \end{cases}
\]

Best Answer

A different solution, which extends the cases environment. It adds an optional argument for defining array column options. The standard cases behavior is the default, so without optional argument it's like the normal amsmath's cases.

\documentclass{article}
\usepackage{amsmath}
\makeatletter
\renewcommand{\env@cases}[1][@{}l@{\quad}l@{}]{%
  \let\@ifnextchar\new@ifnextchar
  \left\lbrace
  \def\arraystretch{1.2}%
  \array{#1}%
}
\makeatother
\begin{document}
\[
  f(x) = \begin{cases}[@{}l@{\quad}r@{}l@{}]
    mx^2 +nx +1, & &x \le -1 \\
    2m e^{|x|-1} + \sin \pi x - 3n, & -1 < {} &x < 1 \\
    3x^2 - (m+n)x, & &x \ge 1
  \end{cases}
\]
\end{document}

redefined cases environment with different alignment

Related Question