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.

a+a+⋯+a⏟n times=nax+y⏞=1+z\underbrace{a + a + \dots + a}_{n \text{ times}} = na \qquad \overbrace{x + y}^{= 1} + z

Open this formula in the editor

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+b⏞u+c+d⏞v⏟w\underbrace{\overbrace{a + b}^{u} + \overbrace{c + d}^{v}}_{w}

Open this formula in the editor

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.

a+b⏟a long explanation+ca+b⏟a long explanation+ca + \underbrace{b}_{\text{a long explanation}} + c \qquad a + \underbrace{b}_{\mathclap{\text{a long explanation}}} + c

Open this formula in the editor

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}
\]
Result
The compiled example

Open in the editor

Pitfalls

Compiled with pdfLaTeX from TeX Live 2023.

Related pages