How to vertically align underbraces

I am trying to balance underbraces in the equation below, how can I ensure that both underbraces at the same depth?

$$y = \underbrace{ \left [ x^2 + r^2 (a^2+\frac{a^{0.3}}{b}) \right]}_\text{growth rate} \times \underbrace{ C_0}_\text{initial}$$

• Commented Jan 16, 2014 at 17:06

One way to solve this is to insert a "vertical phantom" -- an object with a certain height and depth but no width and therefore invisible, hence its name "phantom" -- in the second \underbrace expression.

In the case at hand, an immediately ready argument for such a \vphantom is the tallest "math molecule" from the first \underbrace expression; this turns out to be the term \left(\frac{a^{0.3}}{b}\right).

I would also like to suggest that you encase both \underbrace expressions in their entirety in curly braces; this'll improve the horizontal spacing around the \times symbol.

Addendum, Dec. 2019: The word "initial" is wider than the material immediately above it. This causes an unnecessarily wide gap to open up between the material in large square brackets and C_0. In the second row of the following screenshot, a \mathclap directive is used to set the width of "initial" to 0, leading to a better amount of horizontal spacing.

\documentclass{article}
\usepackage{mathtools} % for '\mathclap' macro
\begin{document}
\begin{align}
y
&= {\underbrace{%
\left[ x^2 + r^2 \left(a^2+\frac{a^{0.3}}{b}\right) \right]
}_{\text{growth rate}}}
\times
{\underbrace{%
\vphantom{ \left(\frac{a^{0.3}}{b}\right) }
C_0}_{\text{initial}}}\\
&= {\underbrace{%
\left[ x^2 + r^2 \left(a^2+\frac{a^{0.3}}{b}\right) \right]
}_{\text{growth rate}}}
\times
{\underbrace{%
\vphantom{\left(\frac{a^{0.3}}{b}\right)}
C_0}_{\mathclap{\text{initial}}}}
\end{align}
\end{document}

• For the reader (I know Mico knows this already :-)): You don't need to put the whole exact same expression into the phantom, you could box it the first time, and then \copy the box. Or go with what Werner did in his (now deleted) answer; instead of \left[<sub expression>\right], he used \bigl[ in the formula, so he just used only \bigl[ with the phantom, which is shorter to type. Commented Jan 16, 2014 at 14:11
• @morbusg - Indeed, if one happens to know the exact height and depth of the required vphantom, it's certainly much more straightforward to enter this piece of information directly rather than to insert some block of code. :-) At any rate, I wouldn't recommend inserting various phantoms until a very late stage, when the document is almost completely finished. If one starts engaging in visual formatting of this type earlier on, there's a serious risk one will have to redo the phantoms every time a formula changes in some significant way.
– Mico
Commented Jan 16, 2014 at 14:34
• Oh my god, how clever.
– Hans
Commented Oct 7, 2015 at 2:39
• How to use the under brace to specify each term of the above mentioned equation line by line from right to left.
– M S
Commented Feb 4, 2016 at 13:20

For just two braces the following is perhaps too much, but with three or more items it would become quite inconvenient to guess the largest item and to repeat \vphantom several times.

\documentclass{article}
\usepackage{amsmath,mathtools}

\newcommand{\ubrace}[2]{{\underbrace{#1}_{#2}}} % to avoid weird spacings

\newcommand{\pder}[2]{\frac{\partial#1}{\partial#2}}% for the second example

\ExplSyntaxOn

\NewDocumentCommand{\multiubrace}{mmm}
{% #1 = items, #2 = descriptions, #3 = separators
% #1, #2 and #3 are lists of braced groups
% #1 and #2 should have the same number of items, #3 one less
\egreg_multiubrace:nnn {#1} {#2} {#3}
}

\cs_new_protected:Nn \egreg_multiubrace:nnn
{
\int_step_inline:nn { \tl_count:n {#1} }
{
% print the items with appropriate \vphantom
\ubrace
{% the item
\vphantom{#1} \tl_item:nn {#1} {##1}
}
{% the description
\tl_item:nn {#2} {##1}
}
% the separator
\tl_item:nn {#3} {##1}
}
}

\ExplSyntaxOff

\begin{document}

The example in the question
$y = \multiubrace { { \left [ x^2 + r^2 (a^2+\frac{a^{0.3}}{b}) \right] } { C_{0} } } { { \text{growth rate} } { \mathclap{\text{initial}} } } { {\times} }$

And a more complicated one % https://tex.stackexchange.com/a/711734/4427
$\pder{\mathbf{M}}{t}=- \multiubrace { { \gamma \mathbf{M} \times \mathbf{B}_{\textup{eff}} } { \frac{\alpha}{M} \mathbf{M} \times \pder{\mathbf{M}}{t} } { \theta_i^{S H} c_i^j \mathbf{M} \times \mathbf{M} \times \hat{y} } } { {\textup{precession}}{\textup{damping}}{\textup{SHE STT}} } { {+}{+} }$

\end{document}


• The logic is correct, but ■ the input format is slightly inconvenient (you have to shuffle the input around --- first the text above underbrace, then the text below underbrace, then the text in-between ■ and also the performance might suffer (#1 and \tl_item:nn is evaluated once per underbrace, which makes it quadratic time in the number of items, although this can be easily solved with a savebox) Commented May 11 at 3:21