Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sometimes I want to describe portions of an equation using \underbrace and \overbrace in such a way that the portions are not completely distinct, for example:

        /-------\
x = A + B + C + D + E
    \-------/   \---/

What is the best way to do this?

share|improve this question

5 Answers 5

up vote 20 down vote accepted

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).

share|improve this answer
    
This does help, but as far as I can tell only in the case where you want the first brace to start at the beginning of the line and you only want two braces that overlap. Am I correct, or is there a way to generalize this more? –  Michael Underwood Jul 27 '10 at 13:41
1  
@Michael No, why? Anything like $$0+ \lefteqn{\overbrace{\phantom{1+2+3}}}1+ \underbrace{2+3+\overbrace{x+y+z}+ \lefteqn{\overbrace{\phantom{4+5}}}4}+5$$ works just fine. –  Grigory M Jul 27 '10 at 16:31
    
The only caveat is that one should be careful when using it in inline math: \lefteqn switches font to \displaystyle so one has to use \lefteqn{\textstyle ...}. –  Grigory M Jul 27 '10 at 16:33
    
Thanks, Grigory! Could you please edit your answer to include an example such as this, and a short explanation of how to construct it? I think that would be really helpful here. –  Michael Underwood Jul 27 '10 at 16:44
    
@Michael I've updated the answer to include some useful info from comments. As for explanation of how to construct such things (it seems I can't make it short and easy to understand so) I hope that everything will be clear from examples. –  Grigory M Jul 27 '10 at 17:07

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.

share|improve this answer
    
Thanks Andrew, I hadn't actually seen tikz before so that's a neat introduction to something I probably want to look into more now. It is a little cumbersome though for this particular application, since you'd then also have to place the text next to the brace manually. Also, the braces seem quite a bit taller than the ones generated in math mode by \underbrace and just don't look quite 'right' -- although that's subjective, and possibly just because I'm already used to the other ones. –  Michael Underwood Jul 27 '10 at 16:57
    
You can change the amplitude and thickness to suit, though I don't know if it's possible to get them exactly the same as LaTeX would do. When you say "place the text next to the brace manually", do you mean that you want to be able to add text at the point of the brace? (I didn't spot that this was in the spec) If so, that's really easy. Would you like me to add that to my answer? –  Loop Space Jul 27 '10 at 17:52

Check out "LaTeX Mathmode" by Herbert Voß. The manual can be found on CTAN (PDF).

Skip down to section 63.2 "Overlapping braces". He also gives examples of other tricks you may want to pull using braces.

share|improve this answer

For future reference: this overlaps with How to have overlapping under-braces and over-braces both in the question above and in the answers below ;-)

(I would have posted this as a comment, but don't have enough reputation.)

share|improve this answer

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}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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