适合所有环境的案例对齐和显示样式

适合所有环境的案例对齐和显示样式

请考虑以下“最小”代码:

\documentclass{article}
\usepackage{amsmath}% http://ctan.org/pkg/amsmath
\begin{document}\begin{align*}
(p's_y)(z)&=(ps_xs_y)(z)=\\
    &=\begin{cases}
        p'(z)                       &   z\neq y\\
        \sum_{v\in N(y)}p'(v)-p'(z) &       z=y
    \end{cases}\\
    &=\begin{cases}
        p(z)                                            &   z\neq x,y\\
        \sum_{v\in N(x)}p(v)-p(x)                       &   z=x\\
        \sum_{v\in N(y)\setminus\{x\}}p'(v)+p'(x)-p'(y) &   z=y
    \end{cases}\\
    &=\begin{cases}
        p(z)                                            &   z\neq x,y\\
        \sum_{v\in N(x)}p(v)-p(x)                       &   z=x\\
        \sum_{v\in N(y)\setminus\{x\}} p(v) +
        \sum_{v\in N(x)}p(x)-p(x)-p(y)                  &   z=y
    \end{cases}\\
    &=\begin{cases}
        p(z)                                            &   z\neq x,y\\
        \sum_{v\in N(x)}p(v)-p(x)                       &   z=x\\
        \sum_{v\in N(y)\setminus\{x\}} p(v) +
        \sum_{v\in N(x)\setminus\{y\}} p(v) -p(x)       &   z=y
    \end{cases}\\
    &=\begin{cases}
        p(z)                                                        &   z\neq x,y\\
        \sum_{v\in N(x)}p(v)-p(x)                                   &   z=x\\
        \sum_{v\in \left(N(x)\cup N(y)\right)\setminus\{x,y\}} p(v) &   z=y
    \end{cases}
\end{align*}
\end{document}​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​

其结果如下:

在此处输入图片描述

现在我的问题是:

  1. 我如何才能全局设置\displaystyle整个\limits文档和所有环境,而不需要一遍又一遍地声明它(即不需要\displaystyle\sum\limits每次都明确地写...)。
  2. 我怎样才能使所有条件(即z=y...)一致?
  3. cases我怎样才能使(即总和和)的第一列p(x)居中?

答案1

dcases您可以从包装中取出mathtools并测量最大的物品,但在我看来,最终结果比您的图像差得多:

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

\newlength{\longestcase}
\newcommand{\longcase}[1]{%
  \mathmakebox[\longestcase][l]{#1}%
}

\begin{document}

\settowidth{\longestcase}{%
  $\displaystyle
   \sum_{v\in N(y)\setminus\{x\}} p(v) +
   \sum_{v\in N(x)}p(x)-p(x)-p(y)
  $}
\begin{align*}
(p's_y)(z)
  &=(ps_xs_y)(z)=\\
  &=\begin{dcases}
    \longcase{p'(z)}                                 & z\neq y\\[2ex]
    \sum_{v\in N(y)}p'(v)-p'(z)                      & z=y
    \end{dcases}\\
  &=\begin{dcases}
    \longcase{p(z)}                                  & z\neq x,y\\[2ex]
    \sum_{v\in N(x)}p(v)-p(x)                        & z=x\\
    \sum_{v\in N(y)\setminus\{x\}}p'(v)+p'(x)-p'(y ) & z=y
    \end{dcases}\\
  &=\begin{dcases}
    \longcase{p(z)}                                  & z\neq x,y\\[2ex]
    \sum_{v\in N(x)}p(v)-p(x)                        & z=x\\
    \sum_{v\in N(y)\setminus\{x\}} p(v) +
    \sum_{v\in N(x)}p(x)-p(x)-p(y)                   & z=y
    \end{dcases}\\
  &=\begin{dcases}
    \longcase{p(z)}                                  & z\neq x,y\\[2ex]
    \sum_{v\in N(x)}p(v)-p(x)                        & z=x\\
    \sum_{v\in N(y)\setminus\{x\}} p(v) +
    \sum_{v\in N(x)\setminus\{y\}} p(v) -p(x)        & z=y
    \end{dcases}\\
  &=\begin{dcases}
    \longcase{p(z)}                                  & z\neq x,y\\[2ex]
    \sum_{v\in N(x)}p(v)-p(x)                        & z=x\\
    \sum_{v\in (N(x)\cup N(y))\setminus\{x,y\}} p(v) & z=y
    \end{dcases}
\end{align*}

\end{document}​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​

在此处输入图片描述

使物体居中会使情况变得更糟。;-)

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

\newlength{\longestcase}
\newcommand{\longcase}[1]{%
  \mathmakebox[\longestcase][c]{#1}%
}

\begin{document}

\settowidth{\longestcase}{%
  $\displaystyle
   \sum_{v\in N(y)\setminus\{x\}} p(v) +
   \sum_{v\in N(x)}p(x)-p(x)-p(y)
  $}
\begin{align*}
(p's_y)(z)
  &=(ps_xs_y)(z)=\\
  &=\begin{dcases}
    \longcase{p'(z)}                                            & z\neq y\\[2ex]
    \longcase{\sum_{v\in N(y)}p'(v)-p'(z)}                      & z=y
    \end{dcases}\\
  &=\begin{dcases}
    \longcase{p(z)}                                             & z\neq x,y\\[2ex]
    \longcase{\sum_{v\in N(x)}p(v)-p(x)}                        & z=x\\
    \longcase{\sum_{v\in N(y)\setminus\{x\}}p'(v)+p'(x)-p'(y)}  & z=y
    \end{dcases}\\
  &=\begin{dcases}
    \longcase{p(z)}                                             & z\neq x,y\\[2ex]
    \longcase{\sum_{v\in N(x)}p(v)-p(x)}                        & z=x\\
    \longcase{\sum_{v\in N(y)\setminus\{x\}} p(v) +
      \sum_{v\in N(x)}p(x)-p(x)-p(y)}                           & z=y
    \end{dcases}\\
  &=\begin{dcases}
    \longcase{p(z)}                                             & z\neq x,y\\[2ex]
    \longcase{\sum_{v\in N(x)}p(v)-p(x)}                        & z=x\\
    \longcase{\sum_{v\in N(y)\setminus\{x\}} p(v) +
      \sum_{v\in N(x)\setminus\{y\}} p(v) -p(x)}                & z=y
    \end{dcases}\\
  &=\begin{dcases}
    \longcase{p(z)}                                             & z\neq x,y\\[2ex]
    \longcase{\sum_{v\in N(x)}p(v)-p(x)}                        & z=x\\
    \longcase{\sum_{v\in (N(x)\cup N(y))\setminus\{x,y\}} p(v)} & z=y
    \end{dcases}
\end{align*}
\end{document}​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​

在此处输入图片描述

答案2

一种变体,使用该eqparbox包通过标签系统测量最宽的左侧,并使用\smashoperator以下命令测量较少的水平空间mathtools

\documentclass{article}
\usepackage{mathtools}% http://ctan.org/pkg/amsmath
\usepackage{eqparbox}
\newcommand\eqmathbox[2][]{\eqmakebox[#1]{\ensuremath{\displaystyle#2}}}

\begin{document}

\begin{align*}
  (p's_y)(z) & =(ps_xs_y)(z)= \\
                                                                                                      & =\begin{dcases}
  \eqmathbox[C]{p'(z)} & z\neq y \\
  \eqmathbox[C]{\smashoperator[r]{\sum_{v\in N(y)}}p'(v)-p'(z)} & z=y
  \end{dcases}\\[1ex]
                                                                                                      & =\begin{dcases}
  \eqmathbox[C]{p(z)} & z\neq x,y \\
  \eqmathbox[C]{\smashoperator[r]{\sum_{v\in N(x)}}p(v)-p(x)} & z=x \\
  \eqmathbox[C]{\smashoperator[r]{\sum_{v\in N(y)\setminus\{x\}}}p'(v)+p'(x)-p'(y)} & z=y
  \end{dcases}\\[1ex]
                                                                                                      & =\begin{dcases}
  \eqmathbox[C]{p(z)} & z\neq x,y \\
  \eqmathbox[C]{\smashoperator[r]{\sum_{v\in N(x)}}p(v)-p(x)} & z=x \\
  \eqmathbox[C]{\smashoperator[r]{\sum_{v\in N(y)\setminus\{x\}}} p(v) +
  \smashoperator{\sum_{v\in N(x)}}p(x)-p(x)-p(y)} & z=y
  \end{dcases}\\[1ex]
                                                                                                      & =\begin{dcases}
  \eqmathbox[C]{p(z)} & z\neq x,y \\
  \eqmathbox[C]{\smashoperator[r]{\sum_{v\in N(x)}}p(v)-p(x)} & z=x \\
  \eqmathbox[C]{\smashoperator[r]{\sum_{v\in N(y)\setminus\{x\}}} p(v) +
  \smashoperator{\sum_{v\in N(x)\setminus\{y\}}} p(v) -p(x)} & z=y
  \end{dcases}\\[1ex]
                                                                                                      & =\begin{dcases}
  \eqmathbox[C]{p(z)} & z\neq x,y \\
  \eqmathbox[C]{\smashoperator[r]{\sum_{v\in N(x)}}p(v)-p(x)} & z=x \\
  \eqmathbox[C]{\smashoperator[r]{\sum_{v\in \left(N(x)\cup N(y)\right)\setminus\{x,y\}}} p(v)} & z=y
  \end{dcases}
\end{align*}

\end{document} 

在此处输入图片描述

相关内容