# Equal size underbraces at a lower position

I am writing a markdown document and I want to have underbraces of equal size under each term, like the one here:

I could only do it manually by adding a bunch of empty spaces (\ ) around the terms:

$$\underbrace{\ \ \ \ X_t \ \ \ \ }_\text{Population at time t} = \underbrace{\alpha \circ X_{t-1}}_\text{Survivors from time t-1} + \underbrace{\ \ \ \ \epsilon_t \ \ \ \ }_\text{Immigration}$$


Though, it is not efficient to add spaces manually (and investigating visually whether they end up of equal size), and they do not look nice and need to be lowered a bit.:

How can I fix it?

(Please ignore the mismatch of the circle operators; I have posted it elsewhere.)

eqparbox can help with this via it's \eqmakebox[<tag>][<align>]{<stuff>} macro. All <stuff> with the same <tag> is set in a box that is of maximum width. Additional <align>ment can be specified (left, centre or right) on a per-use basis. Not sure whether this will work in Markdown, as it requires at least two compilations with any change in the maximum width of elements using the same <tag>.

I've added \eqmathbox that translates the definition into a math-friendly environment (since there are different styles of display within math mode). If you don't have an up-to-date LaTeX, you should also include xparse (...or update your LaTeX distribution).

\documentclass{article}

\usepackage{eqparbox,amsmath}
%\usepackage{xparse}% If you have LaTeX2e < 2020-10-01

% https://tex.stackexchange.com/a/34412/5764
\makeatletter
% \eqmathbox[<tag>][<align>]{[itex]}
\NewDocumentCommand{\eqmathbox}{o O{c} m}{%
\IfValueTF{#1}
{\def\eqmathbox@##1##2{\eqmakebox[#1][#2]{$##1##2$}}}
{\def\eqmathbox@##1##2{\eqmakebox{$##1##2$}}}
\mathpalette\eqmathbox@{\vphantom{\Big|} #3} % \vphantom{\Big|} added to push the braces lower
}
\makeatother

\begin{document}

$\underbrace{\eqmathbox[Xt]{ X_t }}_\text{Population at time t} = \underbrace{\eqmathbox[Xt]{\alpha \circ X_{t - 1}}}_\text{Survivors from time t - 1} + \underbrace{\eqmathbox[Xt]{ \epsilon_t }}_\text{Immigration}$

\end{document}

• Thanks for the solution and explanation! How can I lower the underbraces, other than adding \vphantom{\Big|}, as @SebGlav suggested above? – ManuHaq Jan 27 at 8:40
• You can access the \parbox height but it's a bit trickier. Follow this link: tex.stackexchange.com/questions/387074/… – SebGlav Jan 27 at 16:54
• @ManuHaq: You can add it (a strut, like \vphantom{\Big|} to the definition of \eqmathbox to hide it from your readable code. – Werner Jan 27 at 17:52
• I see, thanks. I am going to edit that and accept this answer :) – ManuHaq Jan 28 at 10:11

You use a \parbox-based approach along the following lines:

\documentclass{article}
\usepackage{amsmath}
\usepackage{newtxtext,newtxmath} % optional - Times Roman text and math fonts
\newlength\mylen
\settowidth\mylen{$\displaystyle\alpha\circ X_{t-1}$} % measure width of widest element
\newcommand\mybox[1]{\parbox{\mylen}{\centering$\displaystyle #1$}}
\begin{document}
$\underbrace{\mybox{X_t}}_{\text{Population at time t}} = \underbrace{\mybox{\alpha\circ X_{t-1}}}_{\text{Survivors from time t-1}} + \underbrace{\mybox{P\epsilon_t}}_{\text{Immigration}}$
\end{document}

• Clever, and way better than my solution ;) – SebGlav Jan 26 at 20:05
• Thanks. Isn't there a more general/straightforward solution that can be applied elsewhere, without having to specifically setting $\mylen$? Imagine somewhere else I have another equation with a wider term. – ManuHaq Jan 26 at 20:15
• @ManuHaq - I'm afraid you need to be a bit more specific as to what it is you wish to achieve. The example above uses one \settowidth instruction because there's just one equation; if there are two equations in the document, you can just run a second \settowidth instruction. Observe that it would not be necessary to redefine the \mybox macro. If you're averse to measuring the width of the widest element to be under-braced directly, you're entirely free to choose some arbitrary length that's as least as large as \mylen. – Mico Jan 26 at 20:20
• I found this solution the better, and it's very understandable. It computes the length of the biggest brace and adjusts the others accordingly. I can't see anything more straightforward. – SebGlav Jan 27 at 16:53

One very ugly way to do it is to cheat with some \vphantom. Please note that you can also insert horizontal spaces with \hspace* instead of a series of backslashes. There is probably a better way to achieve all this but, for a start...

\documentclass{article}
\usepackage{amsmath}

\begin{document}
$$\underbrace{\vphantom{\Big|} \hspace*{5mm} X_t \hspace*{5mm}}_\text{Population at time t} = \underbrace{\vphantom{\Big|}\alpha \circ X_{t-1}}_\text{Survivors from time t-1} + \underbrace{\vphantom{\Big|} \hspace*{5mm} \epsilon_t \hspace*{5mm}}_\text{Immigration}$$

\end{document}


You can define \ubrace macro and use \def\ubracew{max-width-formula} before each such formula inside math mode.

\def\ubrace#1#2{%
\setbox0=\hbox{$\displaystyle\ubracew$}%
\underbrace{\hbox to\wd0{\hss$\displaystyle#1$\lower.8ex\hbox{}\hss}}%
_{\text{#2}}%
}

$$\def\ubracew{\alpha\circ X_{t-1}} \ubrace{X_t}{Population at time t} = \ubrace{\alpha \circ X_{t-1}}{Survivors from time t-1} + \ubrace{\epsilon_t}{Immigration}$$