Underbrace and overbrace in LaTeX
\underbrace{...}_{label} draws a horizontal brace under a part of a formula and puts the label below it. \overbrace{...}^{label} does the same above the formula.
Preamble
The snippets on this page need these lines before \begin{document}:
\usepackage{mathtools}Brace with a label
The label is attached with _ to \underbrace and with ^ to \overbrace. It is in math mode, so words go into \text{...} from amsmath. Both brace commands are part of LaTeX.
\[
\underbrace{a + a + \dots + a}_{n \text{ times}} = na
\qquad
\overbrace{x + y}^{= 1} + z
\]Change the formula
The preview is drawn in your browser by KaTeX, which knows the common math commands. The editor compiles the formula with pdfTeX.
Braces above and below, nested
A braced part can contain further braces. Each brace covers its whole argument.
\[
\underbrace{\overbrace{a + b}^{u} + \overbrace{c + d}^{v}}_{w}
\]Change the formula
The preview is drawn in your browser by KaTeX, which knows the common math commands. The editor compiles the formula with pdfTeX.
A label that is wider than the brace
A wide label pushes the neighbouring terms apart. \mathclap{...} from mathtools sets the label with a width of zero, so it sticks out on both sides and the formula keeps its spacing.
\[
a + \underbrace{b}_{\text{a long explanation}} + c
\qquad
a + \underbrace{b}_{\mathclap{\text{a long explanation}}} + c
\]Change the formula
The preview is drawn in your browser by KaTeX, which knows the common math commands. The editor compiles the formula with pdfTeX.
Square brackets and lines
\underbracket and \overbracket from mathtools draw square brackets and take labels in the same way. \overline and \underline draw a plain line.
\[
\underbracket{a + b}_{\text{sum}}
\qquad
\overbracket{c + d}^{\text{sum}}
\qquad
\overline{a + b}
\qquad
\underline{x}
\]Pitfalls
- The braced part has to start and end in the same cell: it cannot contain an
&or a\\ofalign. - In a line of text a brace with a label makes the line much taller. Use a display formula.
Compiled with pdfLaTeX from TeX Live 2023.
Related pages
- Package
mathtools - Package
amsmath - How-to Text in math mode in LaTeX
- How-to Cancel terms in an equation in LaTeX
- How-to Large brackets in LaTeX