6

I do not like that \begin{cases} \end{cases} only allows for one alignment tab, as I usually want to use two.

\left\{
\begin{array}{rlr}
  a & = c & x=1 \\
  b & = d & x=2 1 
\end{array}
\right.

Is it possible to redefine cases (or define a new environment) such that I could just write

\begin{mycases} 
     a & = c & x=1\\ 
     b & = d & x=2
\end{mycases}

or something similarly simple?

flawr
  • 1,123
  • 1
  • 9
  • 19

3 Answers3

8

Yes. Use alignat and empheq(needless to load amsmath in this case):

\documentclass{article}
\usepackage[utf8]{inputenc}%
\usepackage{empheq}

\begin{document}

\begin{empheq}[left=\empheqlbrace]{alignat*=2}
  a & = c, &\qquad x&=1,\\
  b + b’ & = d + d’, & x&=2.
\end{empheq}

\end{document} 

Note you need 3&. More generally, for n groups of alignment, you need 2n–1 ampersands: one is for the new group (from the 2nd group), the next for the alignment point inside the group.

enter image description here

Bernard
  • 271,350
8

You can simply use your own definition as a new environment.

\documentclass{article}
\begin{document}

\newenvironment{mycases}%
  {\left\{
   \begin{array}{@{}r@{\;}lr@{}}
  }%
  {\end{array}
   \right.
  }

\(\begin{mycases} 
     a & = c & x=1\\ 
     b & = d & x=2
  \end{mycases}
\)
\end{document}

enter image description here

gernot
  • 49,614
6

Yes, just modify suitably the definition of cases:

\documentclass{article}
\usepackage{amsmath,array}

\makeatletter
\newenvironment{mycases}{%
  \let\@ifnextchar\new@ifnextchar
  \left\lbrace
  \def\arraystretch{1.2}%
  \array{@{}r@{}>{{}}l@{\quad}l@{}}%
}{%
  \endarray\right.%
}
\makeatother

\begin{document}

\[
\begin{mycases} 
a+a^2 & = c & x=1\\ 
b & = d-d^2 & x=2
\end{mycases}
\]

\end{document}

enter image description here

egreg
  • 1,121,712
  • Thank you very much, this definition seems to be a little bit more complicated than the one @gernot posted. Is there a difference? – flawr Sep 29 '16 at 20:46
  • @flawr The definition is complicated, but the input style is simpler. – egreg Sep 29 '16 at 21:09