211

How do I put big brackets under different parts of an equation so that I can write, e.g., text specific to these parts?

For example:

f =  x^3 +  2
    |___|  |__| 
      |     |
   text 1  text 2

COTO
  • 371
  • Welcome to TeX.sx! Your question was migrated here from [so]. Please register on this site, too, and make sure that both accounts are associated with each other, otherwise you won't be able to comment on or accept answers or edit your question. – Werner Feb 17 '12 at 04:47
  • 2
    The question mentions "brackets", while the answers below provide "braces". For a bracket approach, there is this question: http://tex.stackexchange.com/questions/161459/how-to-link-two-terms-in-math-mode – Steven B. Segletes Jan 22 '15 at 00:06

3 Answers3

267

Since the text used in \underbrace (or \overbrace) is typically set in a different font size to not distract further from the equation, it is preferable to use amsmath's \text macro.

enter image description here

\documentclass{article}
% \usepackage{amsmath}
\usepackage{mathtools}% Loads amsmath
\begin{document}
\[
  f(x) = 
    \underbrace{(x + 2)^3}_\text{text 1} + 
    \bigl(
      \mathrlap{\overbrace{\phantom{(c - 2d)}}^{\text{text 2}}}
      (c - 
      \mathrlap{\underbrace{\phantom{2d) + (3e}}_{\text{text 3}}}
      2d) +
      \overbrace{(3e - 4f)}^{\text{text 4}}
    \bigr) + 
    \overbrace{(x - 3)}^\text{text 5}
\]
\end{document}

The difficult overlapping braces uses math overlaps from mathtools. It follows a process of setting the \over-/\underbrace text first with a \phantom base, after which the base (or part thereof) is re-set. However, if those aren't needed, using amsmath only would suffice for usage of \text.

There are a number of ways of achieving the overlapping output. Another method of overlapping braces is discussed in section 63.2 Overlapping braces of the mathmode document.

Werner
  • 603,163
  • 1
    Would you still use \text if you wanted to include math? e.g., instead of "text 1" I want to have something like $g(x)$. (Also, congrats on your 1000th answer. Awesome work!) –  Feb 17 '12 at 06:12
  • @MikeWierzbicki: Thanks - 1000! No, if you use math, then you would not use \text, since math will automatically size to the appropriate font size. The switching of mode (from math to text) causes default settings to be invoked, setting text in \normalsize rather than \scriptsize. amsmath's \text chooses the appropriate text font size via \mathchoice. – Werner Feb 17 '12 at 06:28
  • 1
    Perhaps the single most useful answer on this entire forum – Fraïssé Jul 20 '16 at 01:24
  • 1
    Good, answer, but how can I add equations since \text is used. – GoingMyWay Oct 05 '19 at 14:38
  • @GoingMyWay: You're going to have to show what you're after, since it's not clear from your comment. – Werner Oct 05 '19 at 16:12
  • I mean if you want to add equations, use \underbrace{}_{\mathrm{}}instead of\text` – GoingMyWay Oct 05 '19 at 16:23
  • @GoingMyWay: You're going to have to be a bit more verbose than that. Whether you use \mathrm or \text, it should not make a difference, unless the annotation is wider than its base. At that point, you would probably use \mathclap to hide the horizontal length. – Werner Oct 08 '19 at 20:42
  • Any ideas on how to insert a breakline inside the \text{} object under the \underbrace? – Tropilio Jun 09 '20 at 13:10
  • 1
    @Tropilio: You can use a tabular, or array, or substack. – Werner Jun 09 '20 at 18:53
45

What you want is

f = \underbrace{x^3}_\textrm{text 1} + \underbrace{2}_\textrm{text 2}
Thorsten
  • 12,872
Tristan
  • 661
  • 3
    NB syntax for overbraces, \overbrace{x^2}^\text{over} – innisfree Sep 13 '17 at 07:57
  • 1
    For those who might be interested, with Beamer, the subcript \textrm{..} needs to be enclosed with braces: \underbrace{x^3}_ { \textrm{text 1} } otherwise it seems that there is a compilation error. – zetyty Sep 01 '22 at 12:21
4

You would find it out in the mathmode manual or symbols manual.

lucidbrot
  • 305
  • 4
    Please provide hyperlinks for the manuals. Not everybody may know where to find them. (I've added them for you.) Also you should consider providing more information. The poster may not know what to look for. –  Feb 17 '12 at 07:53
  • 5
    The link to mathmode manual gives me a 404. – Reb.Cabin Mar 21 '16 at 19:56