# How to align only some equations in an align environment?

Here's what I got:

\begin{align*}
P[E_{m}] &= P[m] + P[2m] + P[3m] + \dots \\
&= \frac{1}{\varsigma(s)} \langle m^{-s} + (2m)^{-s} + (3m)^{-s} + \dots \rangle \\
&= \frac{1}{\varsigma(s)} \langle \underbrace{1^{-s} + 2^{-s} + 3^{-s} + \dots} \rangle m^{-s} \\
&= \frac{1}{\varsigma(s)} \langle \hspace{13mm} \varsigma(s) \hspace{13mm} \rangle m^{-s} \\
&= m^{-s}
\end{align*}


I now wish to align the last \rangle to the second to last \rangle perfectly and have the \varsigma(s) centered. This without aligning anything to the first \rangle (pretty much as it is now but with perfect and automatic alignment).

I have found this which seemed like what I needed at first but wasn't (as I don't want to align ALL equations to the braces).

You can measure the length of the contents within the \langle-\rangle and position \varsigma(s) accordingly:

\documentclass{article}
\usepackage{mathtools}% http://ctan.org/pkg/amsmath
\newlength{\templen}
\settowidth{\templen}{$1^{-s} + 2^{-s} + 3^{-s} + \cdots$}
\begin{document}
\begin{align*}
P[E_{m}] &= P[m] + P[2m] + P[3m] + \cdots \\
&= \frac{1}{\varsigma(s)} \langle m^{-s} + (2m)^{-s} + (3m)^{-s} + \cdots \rangle \\
&= \frac{1}{\varsigma(s)} \langle
\hspace*{.5\templen}\mathclap{\underbrace{1^{-s} + 2^{-s} + 3^{-s} + \cdots}}\hspace*{.5\templen} \rangle m^{-s} \\
&= \frac{1}{\varsigma(s)} \langle
\hspace*{.5\templen}\mathclap{\varsigma(s)}\hspace*{.5\templen} \rangle m^{-s} \\
&= m^{-s}
\end{align*}
\end{document}


For consistency I've spaced the \underbrace inside a \mathclap as well, since there is otherwise a minor misalignment.

The idea behind this approach is to step halfway into the expected width, then use \mathclap to place content in math-mode, centered in a zero-width box, and then complete the width-adjustment with another step the remaining half-width.

You can also mark the position on the page and calculate distances using the savepos module of zref:

\documentclass{article}
\usepackage{mathtools}% http://ctan.org/pkg/amsmath
\usepackage{zref-savepos}% http://ctan.org/pkg/zref
\makeatletter
% \zsaveposx is defined since 2011/12/05 v2.23 of zref-savepos
\@ifundefined{zsaveposx}{\let\zsaveposx\zsavepos}{}
\makeatother
\newcounter{hposcnt}
\renewcommand*{\thehposcnt}{hpos\number\value{hposcnt}}
\newcommand*{\SPl}{% set left position
\stepcounter{hposcnt}%
\zsaveposx{\thehposcnt spl}%
}
\newcommand*{\SPr}{% set right position
\zsaveposx{\thehposcnt spr}%
}

\makeatother
\begin{document}
\begin{align*}
P[E_{m}] &= P[m] + P[2m] + P[3m] + \cdots \\
&= \frac{1}{\varsigma(s)} \langle m^{-s} + (2m)^{-s} + (3m)^{-s} + \cdots \rangle \\
&= \frac{1}{\varsigma(s)} \langle
\SPl\underbrace{1^{-s} + 2^{-s} + 3^{-s} + \cdots}\SPr \rangle m^{-s} \\
&= \frac{1}{\varsigma(s)} \langle
\makebox[\dimexpr\zposx{\thehposcnt spr}sp-\zposx{\thehposcnt spl}sp]{$\varsigma(s)$} \rangle m^{-s} \\
&= m^{-s}
\end{align*}
\end{document}


It requires you to mark the left and right position using \SPl and \SPr, and then immediately use it to calculate the difference between the points (before setting another left/right mark).

• Thanks, this looks very good. The only drawback is that templen isn't assigned automatically but I doubt a better solution is possible (though I'd love to see me proven wrong). – Balz Guenat Oct 8 '13 at 21:42
• @Coloneljesus: \templen is 96.57271pt, so you could get by using 100pt and therefore leave a 50pt jump on either side. However, if you don't know the width of something you have to measure it first. One could, of course, place labels to mark the horizontal location and space the placement automatically... – Werner Oct 8 '13 at 22:07

Getting your readers to figure out that the object that the \underbrace is supposed to be pointing to is the lonely \varsigma(s) term on the next line down may require some luck, even if the angle brackets are lined up perfectly. It may be wiser to write =\varsigma(s) directly below the underbrace and then provide just a little bit of redundancy in the next line:

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align*}
P[E_{m}] &= P[m] + P[2m] + P[3m] + \dots \\
&= \frac{1}{\varsigma(s)} \langle m^{-s} + (2m)^{-s} + (3m)^{-s} + \dots \rangle \\
&= \frac{1}{\varsigma(s)} \langle\, \underbrace{1^{-s} + 2^{-s} + 3^{-s} + \dots}_{=\varsigma(s)}\, \rangle m^{-s} \\
&= \frac{1}{\varsigma(s)} \langle \varsigma(s) \rangle m^{-s} \\
&= m^{-s}
\end{align*}
\end{document}

• While no answer to my question, this is certainly a good alternative of doing it. Thank you. – Balz Guenat Oct 8 '13 at 21:58