4

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}

enter image description here

Moura
  • 1,555

1 Answers1

5

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}

enter image description here

  • just by the challenge, is it possible to invert the position symbols? – Moura Jun 16 '19 at 15:35
  • 1
    @Moura Do you mean for the braces to embrace the word, rather than the equal sign? – Steven B. Segletes Jun 16 '19 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 '19 at 14:11
  • 1
    @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 '19 at 15:02