# How to ignore the size of the content when using underbrace and overbrace?

Based on the suggestion here How to add an underbrace and overbrace to a term in a equation or here What causes the problem when compiling a displayed equation with \overbrace and \underbrace? for instance, is it possible we have a "small" and the same size the symbols for underbrace and overbrace together?

I was trying to use the code below. Thank you.

\documentclass{article}
\usepackage{amsmath}
\usepackage[x11names, table]{xcolor}

\begin{document}

$\begingroup \color{red}\underbrace{\overbrace{\color{black}=}^{\mathrm{over over over over over}}}_{\mathrm{under}} \endgroup$
\end{document}


• What is the full code that you use, please? – Sebastiano Jun 15 at 22:44
• @Sebastiano, I put a MWE above. Thanks – Moura Jun 16 at 13:50

The use of \mathclap (mathtools package) allows the horizontal width of the content to be ignored.

In the 2nd example, arising from an OP comment, I use stackengine to reverse the sense of the braces. There, I also use \renewcommand\useanchorwidth{T} to ignore the width of the over/under text relative to the equation.

\documentclass{article}
\usepackage{mathtools,stackengine}
\usepackage[x11names, table]{xcolor}
\stackMath
\begin{document}

$\begingroup \color{red} \underbrace{\overbrace{\color{black}=}^{\mathclap{% \mathrm{over over over over over}}}}_{\mathrm{under}} \endgroup$
$x \mathrel{ \renewcommand\useanchorwidth{T} \stackunder{\stackon{=}{\color{red}\underbrace{\scriptscriptstyle\mathrm{ over over over over over}}}}{\color{red}\overbrace{\scriptscriptstyle \mathrm{under}}} } y$
\end{document}


• just by the challenge, is it possible to invert the position symbols? – Moura Jun 16 at 15:35
• @Moura Do you mean for the braces to embrace the word, rather than the equal sign? – Steven B. Segletes Jun 16 at 17:53
• Your code is perfect. But if we'll use, for example in the code below, the braces get space of integer symbol. [ \int 2x\sqrt{x^2+1}\ dx \mathrel{ \renewcommand\useanchorwidth{T} \stackunder{\stackon{=}{\color{red}\underbrace{\text{$u=x^2+1$}}}}{\color{red}\overbrace{ \text{$du=2xdx$}}} } \int \sqrt{u}\ du] – Moura Jun 17 at 14:11
• @Moura Both \stackunder and \stackon take an optional argument that, in this case, denotes the separation gap between stacked elements. So change \stackunder to \stackunder[8pt] and likewise for \stackon. – Steven B. Segletes Jun 17 at 15:02