11

I'm trying to use the cases environment to show an arbitrary equation. But I noticed that it only allows me to use 2 columns. However, I would require a third column, or perhaps a fourth as well.

An example is shown below:

\begin{equation*}
  \Md_1 \Cup \Md_2=
  \begin{cases}
        \Md_2            & when \ \Md_1 = \nothing \\
        \Md_1            & when \ \Md_2 = \nothing \\
        \Md_1 \cup \Md_2 & otherwise
  \end{cases}
\end{equation*}

What I would like to write is something like this (this does not actually work):

\begin{equation*}
  \Md_1 \Cup \Md_2=
  \begin{cases}
        \Md_2            & when \ \Md_1 = \nothing & where & x = foo    \\
                         &                         &       & y = bar    \\
        \Md_1            & when \ \Md_2 = \nothing & where & z = notfoo \\
        \Md_1 \cup \Md_2 & otherwise               &       &            \\
  \end{cases}
\end{equation*}
3
  • Make your own either using a left right construction plus array or left right plus the aligned env
    – daleif
    Mar 25, 2015 at 20:48
  • For text inside math mode, you should use \text.
    – Werner
    Mar 25, 2015 at 20:48
  • daleif, could you please elaborate? Mar 25, 2015 at 20:52

3 Answers 3

6

I would just use a \phantom to yield a similar alignment. Alternatively, make up your own array with the alignment you require:

enter image description here

\documentclass{article}
\usepackage{amsmath}

\begin{document}

\begin{equation*}
  M_1 \cup M_2 =
  \begin{cases}
        M_2            & \text{when $M_1 = foo$} \\
                       & \text{\phantom{when }$M_2 = bar$} \\
        M_1            & \text{when $M_2 = baz$} \\
        M_1 \cup M_2   & \text{otherwise}
  \end{cases}
\end{equation*}

\begin{equation*}
  M_1 \cup M_2 =
  \setlength{\arraycolsep}{0pt}
  \renewcommand{\arraystretch}{1.2}
  \left\{\begin{array}{l @{\quad} l r l}
        M_2            & \text{when } & M_1 &{}= foo \\
                       &              & M_2 &{}= bar \\
        M_1            & \text{when } & M_2 &{}= baz \\
        M_1 \cup M_2   & \text{otherwise}
  \end{array}\right.
\end{equation*}

\end{document}

The former may not work or be easy in general, but it works in your case. The latter should work in a more general setting.

3
  • How would I add the two extra columns (where x = foo)? Mar 25, 2015 at 21:00
  • 1
    @ChristopheDeTroyer: You would add more elements in the array column specification. For example, l @{\quad} l r l r l would add another two columns - first is right-aligned and the second is left-aligned.
    – Werner
    Mar 25, 2015 at 21:01
  • Thanks. I want to mark both answer as they are both correct but this one seems a little less messy to me (the latter). Thank you! Mar 25, 2015 at 21:14
7

Using only amsmath package, the environement aligned allows you to use as many columns as you want :

\documentclass{article}
\usepackage{amsmath}

\begin{document}
    \begin{equation*}
        M_1 \cup M_2 =
            \begin{cases}
            \begin{aligned}
                M_2 & \text{ when } M_1 = 0 &\text{where } & x = f\\
                    &                       &              & y = b\\
                M_1 & \text{ when } M_2 = 0 &\text{where } & z = n\\
                M_1 \cup M_2 & \text{ otherwise }&         &      \\
            \end{aligned}
        \end{cases}
    \end{equation*}
\end{document}

result using amsmath aligned environment

1
  • You could use aligned for just the "where" clauses Nov 21, 2017 at 11:37
6

I probably would find a different way to express my ideas. Anyway, here's a possibility:

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

\makeatletter
\newenvironment{mcases}[1][l]
 {\let\@ifnextchar\new@ifnextchar
  \left\lbrace
  \def\arraystretch{1.2}%
  \array{@{}l@{\quad}#1@{}}}
 {\endarray\right.}
\makeatother

\begin{document}

\begin{equation*}
M_1 \Cup M_2=
\begin{mcases}[ll@{\ }l]
  M_2          & \text{when $M_1 = \emptyset$} & \text{where} & x = f \\
               &                               &              & y = b \\
  M_1          & \text{when $M_2 = \emptyset$} & \text{where} & z = n \\
  M_1 \cup M_2 & \multicolumn{3}{@{}l}{\text{otherwise}}
\end{mcases}
\end{equation*}

\end{document}

Without an optional argument, mcases is the same as cases. The optional argument should specify the column types after the first, which is fixed.

enter image description here

You must log in to answer this question.

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