How can I get an underbrace and an overbrace to partially overlap in an equation?

One can use commands \phantom and \lefteqn.

Simple example: \[\lefteqn{\overbrace{\phantom{1+2+3}}}1+\underbrace{2+3+4}\].

More complicated example:

\[
0+\lefteqn{\overbrace{\phantom{1+2+3}}}1+
\underbrace{2+3+\overbrace{x+y+z}+
\lefteqn{\overbrace{\phantom{4+5}}}4}+5
\]

Caveat: \lefteqn switches font to \displaystyle so one has to use something like \lefteqn{\textstyle... in inline formulas.

P.S. The recipe is taken from the excellent book by S.Lvovski (http://www.mccme.ru/free-books/llang/newllang.pdf, in Russian).


This may not be the best solution, due to the overhead, but this is quite simple using TikZ. You insert invisible nodes at the points where you want the under and over braces to anchor to and then draw the braces between them. In my preamble, I have:

\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing,decorations.pathmorphing,calc}
\newcommand{\tikzmark}[1]{\tikz[overlay,remember picture] \node (#1) {};}

(Obviously, the name can be shortened if this is to be used a lot. I'm not sure off the top of my head which of the decorations library is needed; the calc one is optional but extremely useful.) Then, I would typeset your example using:

\[
x = \tikzmark{ubl} A + \tikzmark{obl} B + C \tikzmark{ubr} + \tikzmark{ubll} D \tikzmark{obr} + E \tikzmark{ubrr}
\]

\begin{tikzpicture}[overlay, remember picture]
\draw[decoration={brace,amplitude=10},decorate,thick] ($(ubl)+(-0.25,-1)$) -- ($(ubr)+(-0.25,1.2)$);
...
\end{tikzpicture}

Reversing the order of the nodes flips the brace, so if that's the wrong way up then simply swap them. The stuff with the dollars is from the calc tikz library. What the above does is specify an offset from the node, so that if you find the default position of the braces a little off (which it probably is), it is simple to adjust them.

I use this a lot in lectures: for adding strike-outs to things, for better-looking brackets on huge matrices, for all sorts of things where you want to add a little graphical decoration afterwards.

For more details, search for 'remember picture' in the TikZ manual, and browse the examples at http://texample.net.


Use the package oubraces. You should get

enter image description here

from

\documentclass{article}
\usepackage{amsmath}
\usepackage{oubraces}
\begin{document}
\[ x=\overunderbraces{&&\br{3}{}}%
{&A+&B+C&+&D&+E}%
{&\br{2}{}& &\br{2}{}}
\]
\end{document}