15

You can see there is an unwanted white space at the last term below.

enter image description here

\documentclass[border=12pt]{standalone}
\usepackage{amsmath}
\begin{document}
$
\lefteqn{\textstyle\overbrace{\phantom{1+2+3+4}}^{\alpha}}1+2+
    \underbrace{3+4+
        \lefteqn{\textstyle\overbrace{\phantom{5+6+7}}^{\beta}}5+6}_{\gamma}+7
$
\end{document}

What causes the white space? And how to remove it?

18

The boxing interferes with the math spacing, if you make the phantoms visible you see what is being braced:

If you correct for the mathop spacing you can make them align exactly:

enter image description here

\documentclass[border=12pt]{article}
\usepackage{amsmath,color}
\begin{document}
$
\lefteqn{\textstyle\overbrace{\phantom{1+2+3+4}}^{\alpha}}1+2+
    \underbrace{3+4+
        \lefteqn{\textstyle\overbrace{\phantom{5+6+7}}^{\beta}}5+6}_{\gamma}+7
$


\def\xphantom#1{\hbox{{\color{red}$#1$}}}
$
\lefteqn{\textstyle\overbrace{\xphantom{1+2+3+4}}^{\alpha}}1+2+
    \underbrace{3+4+
        \lefteqn{\textstyle\overbrace{\xphantom{5+6+7}}^{\beta}}5+6}_{\gamma}+7
$

$\setbox0\hbox{$3+4$}
\overbrace{1+2+3+4}^{\alpha}
\kern-\wd0\!
\underbrace{3+4+5+6}_{\gamma}
\kern-\wd0\!
\overbrace{5+6+7}^{\beta}
$
\end{document}

See the discussion in

How to fix the math-spacing when a lot of \phantom, \mathrlap, etc. are used?

5

I've just released a new package designed to solve just this problem! It is called underoverlap.

Here's how I would then set your example:

$
    \UOLoverbrace{1+2+}[3+4]^\alpha \UOLunderbrace{+}[5+6]_\gamma \UOLoverbrace{+7}^\beta
$

enter image description here

It needs no duplication in your source code and spacing is automatically correct in most cases (mostly thanks to David's help in the question he links to in his answer.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.