超过两列 amsmath 案例

超过两列 amsmath 案例

我正在尝试使用cases环境来显示任意方程。但我注意到它只允许我使用 2 列。但是,我需要第三列,或者也许还需要第四列。

一个例子如下所示:

\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*}

我想写的是这样的(这实际上不起作用):

\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*}

答案1

我只想使用 a来产生类似的对齐。或者,使用您需要的对齐来\phantom自己构造:array

在此处输入图片描述

\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}

前者可能通常不起作用或不容易,但对你的情况有用。后者应该在更一般的环境中起作用。

答案2

仅使用 amsmath 包,环境对齐允许您使用任意数量的列:

\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}

使用 amsmath 对齐环境的结果

答案3

我可能会找到其他方式来表达我的想法。无论如何,这是一种可能性:

\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}

如果没有可选参数,mcases则与 相同cases。可选参数应在第一个参数之后指定列类型,该参数是固定的。

在此处输入图片描述

相关内容