# \underbrace and align environment

I want to typeset a proof and want to emphasize what I do in each step e.g. by underbracing an equal-sign when I substitute a variable. In addition I also want to align equal-signs in every line. Unfortunately I don't know how to align an underbraced equal-sign and a non underbraced equal-sign at the same time.

Question: How can I align the underbraced and the non underbraced equal-sign vertically?

\documentclass{report}

\usepackage{amsmath} % Mathe
\usepackage{mathtools} % Mathe
\usepackage{amsfonts} % Mathesymbole

\begin{document}

\begin{align*}
D(D^TD)^{-1} &\underbrace{=}_{\mathclap{D=B(B^TB)^{-1}}} B(B^TB)^{-1}((B(B^TB)^{-1})^TB(B^TB)^{-1})^{-1} \          &= B(B^TB)^{-1}(((B^TB)^{-1})^TB^TB(B^TB)^{-1})^{-1}
\end{align*}

\end{document}

-
Use a \dagger or something similar for pseudo-inverses. It will be impossible to read if you do that. – percusse Apr 24 '13 at 10:36
It is not a pseuso inverse B^T*B is a regular (square) matrix, so the inverse is well-defined. I want to show that if L(D)=L(B(B^T*B)^{-1}) is a lattice (discrete additive subgroup of R^m) then L(B) is the dual lattice of L(D). For more information see exercise 4 in this lecture note. – patrickvogt Apr 24 '13 at 10:43
I wouldn't even use the underbrace. Instead mention it in the text before or after the formula. Adding an underbrace to explain an equality does not look nice typographically. – daleif Apr 24 '13 at 12:13

You need first of all to make the \underbrace a math relation, for spacing; but you also have to extend the space reserved to it, because an underbrace has a minimum width:

\documentclass{report}

\usepackage{amsmath} % Mathe
\usepackage{mathtools} % Mathe
\usepackage{amsfonts} % Mathesymbole
\usepackage{calc}

\newcommand{\ueq}[1][]{%
\if\relax\detokenize{#1}\relax
\sbox0{$\underbrace{=}_{}$}%
\mathrel{\mathmakebox[\wd0]{=}}
\else
\mathrel{\underbrace{=}_{\mathclap{#1}}}
\fi}

\begin{document}

\begin{align*}
D(D^TD)^{-1} &\ueq[D=B(B^TB)^{-1}] B(B^TB)^{-1}((B(B^TB)^{-1})^TB(B^TB)^{-1})^{-1} \\
&\ueq B(B^TB)^{-1}(((B^TB)^{-1})^TB^TB(B^TB)^{-1})^{-1}
\end{align*}

\end{document}


So, if \ueq has no optional argument it produces an equal sign as wide as an underbraced one, otherwise it adds the underbrace.

-

Here is an alternative to what you want, which still conveys the same information without decorating equals signs with equations. The traditional way to annotate steps in a derivation is with labels. So you could instead do

\documentclass{report}

\usepackage{amsmath} % Mathe
\usepackage{mathtools} % Mathe
\usepackage{amsfonts} % Mathesymbole

\begin{document}
\begin{align}
D(D^TD)^{-1}
&= B(B^TB)^{-1}((B(B^TB)^{-1})^TB(B^TB)^{-1})^{-1}  \label{subst}\          &= B(B^TB)^{-1}(((B^TB)^{-1})^TB^TB(B^TB)^{-1})^{-1} \label{trans}
\end{align}
Here \eqref{subst} is due to the substitution $D=B(B^TB)^{-1}$, and \eqref{trans} is by the transpose law for matrix multiplication.
\end{document}


-

This seems to work

$$\arraycolsep 0pt \begin{array}{lcl} D(D^TD)^{-1} &\underbrace{=}_{\mathclap{D=B(B^TB)^{-1}}} & B(B^TB)^{-1}((B(B^TB)^{-1})^TB(B^TB)^{-1})^{-1} \\ &= & B(B^TB)^{-1}(((B^TB)^{-1})^TB^TB(B^TB)^{-1})^{-1} \end{array}$$


-