# \underbrace spacing

I am currently using the \underbrace command and would like to center \cdot between the two terms. How can I better format this dot product and also line up the underprice text to the same heights?

Thank you.

\begin{equation*}
g'(t)=Df_{\gamma(t)}\left(\gamma'(t)\right)=\underbrace{\nabla f_{\gamma(t)}}_{\text{gradient}} \cdot \underbrace{\gamma'(t)}_{\text{tangent to level line}}
\end{equation*}

Add an appropriate \vphantom and flatten the longer text horizontally:

\documentclass{article}

\usepackage{amsmath}

\begin{document}

$$g'(t) = Df_{\gamma(t)} \bigl( \gamma'(t) \bigr) = \underbrace{\nabla f_{\gamma(t)}}_{\text{gradient}} \hspace{1.5em} \cdot \hspace{1.5em} \underbrace{\vphantom{f_{()}}\gamma'(t)}_{\text{\makebox[0pt]{tangent to level line}}}$$

\end{document}

You could also alternate the brace direction:

\documentclass{article}

\usepackage{amsmath}

\begin{document}

$$g'(t) = Df_{\gamma(t)} \bigl( \gamma'(t) \bigr) = \underbrace{\nabla f_{\gamma(t)}}_{\text{gradient}} \cdot \overbrace{\gamma'(t)}^{\text{\makebox[0pt]{tangent to level line}}}$$

\end{document}

A full working example:

\documentclass{article}

\usepackage{amsmath}
\usepackage{calc}

\begin{document}

\newlength{\lowerlength}
\newlength{\upperlength}
\newlength{\correction}
\setlength{\upperlength}{\widthof{$\gamma'(t)$}}
\setlength{\lowerlength}{\widthof{\scriptsize tangent to level line}}
\setlength{\correction}{(\lowerlength-\upperlength)*\real{0.5}}

\begin{equation*}
g'(t)=Df_{\gamma(t)}\left(\gamma'(t)\right)=\underbrace{\nabla f_{\gamma(t)}}_{\text{gradient}} \;\quad\cdot\quad\; {\underbrace{\gamma'(t)\llap{\phantom{$_{()}$}}}_{\hspace{-\correction}\text{tangent to level line}\hspace{-\correction}}}
\end{equation*}
\end{document}

The calc package can be used to calculate with lengths, and it provides an easy method of computing lengths of text. Adding negative space to the subscript prevents the second factor from moving too far right.

To align the two underbraces vertically, we need to make both factors seem to have the same height. The crucial point here are the parentheses in the subscript of the first factor. So we add them to the second factor invisibly (\phantom) and let TeX ignore their height (\llap).