# aligned overset

The aligned-overset package provides correct alignment for \overset or \underset, respectively. My question however is how to align something which contains BOTH:

\documentclass{article}
\usepackage[utf8]{inputenc}

\usepackage{amsmath}
\usepackage{aligned-overset}

\begin{document}

\begin{align*}
\overset{\text{over}}&{=} g + h\\
\underset{\text{under}}&{=} h + i\\
% not properly aligned
\underset{\text{under}}&{\overset{\text{over}}{=}} f + g\\
% not supported:
% \underset{\text{under}}{\overset{\text{over}}}&{=} f + g\\
\end{align*}

\end{document}


Has anyone an idea how to make this work?

The reason the equals sign isn't aligned for the line with both under- and overset elements is that the width of the "second" element (the "over" one here) is greater than the width of the equals sign.

To reduce the width of the "over" element, apply \mathclap (requires mathtools, which can replace amsmath because it loads that package) to the "over" text, as in this updated example:

\documentclass{article}
\usepackage[utf8]{inputenc}

\usepackage{mathtools}
\usepackage{aligned-overset}

\begin{document}

\begin{align*}
\overset{\text{over}}&{=} g + h\\
\underset{\text{under}}&{=} h + i\\
% not properly aligned
\underset{\text{under}}&{\overset{\text{over}}{=}} f + g\\
\underset{\text{under}}&{\overset{\mathclap{\text{over}}}{=}} f + g\\
\end{align*}

\end{document}


In order to get the correct spacing after the embellished equals sign, the \mathclap should always be applied to the narrower over/under element. This may involve switching the order in which over- and underset are applied, so that the narrowed element always follows the & so that it is associated with the =

• Ah right, I forgot about \mathclap. I hoped there would be something even more convincing, as this workaround is kinda annoying if one deals with words of similar length, but hey...
– J.N.
Dec 24 '19 at 15:24