# Cases alignment and displaystyle for all environments

please consider following "minimal" code:

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


Which turns into following:

So now to my questions:

1. How can I globally set \displaystyle and \limits for the whole document and all environments without declaring it again and again (i.e. without explicitly writing \displaystyle\sum\limits... every time).
2. How can I make all the condidions (i.e. z=y...) align?
3. How can I make the first column of the cases (i.e. the summs and p(x)) centered?
-
\usepackage{mathtools} and dcases environment. – egreg Feb 15 at 17:09
However, rather than repeating cases I'd split the computations in the three cases and show only a final cases (or dcases) environment. – egreg Feb 15 at 17:13
ok thx dcases eases problem 1. So theres still 2 and 3 to go. any other suggestions? – zivimo Feb 15 at 17:18

You can do it with dcases from the mathtools package and measuring the largest item, but the final result is much worse than your image, in my opinion:

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


Centering the objects makes it even worse. ;-)

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


-
I'm sorry for not meeting your taste but to me is seems prettier. Anyway... any change to center stuff? – zivimo Feb 15 at 17:36
@zivimo Yes, it's possible to make it arbitrarily ugly. ;-) – egreg Feb 15 at 17:47

A variant, using the eqparbox package to measure the widest left side with a system of tags, and less horizontal space with the \smashoperator command from 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}


-