How to align only some equations in an align environment?
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, c
entered 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).
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}