請考慮以下“最小”代碼:
\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}
變成如下:
現在我的問題是:
- 如何為整個文件和所有環境全域設定
\displaystyle
and ,\limits
而無需一次又一次聲明(即無需\displaystyle\sum\limits
每次都明確寫入...)。 - 我怎樣才能使所有條件(即
z=y
......)對齊? - 如何使
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}