Underbrace and Overbrace in LaTeX: \underbrace, \overbrace and Annotations
Quick answer
- Brace below:
\underbrace{a+b}_{\text{sum}}in math mode;\textneeds amsmath. - Brace above:
\overbrace{a+b}^{\text{sum}}. - Nested:
\underbrace{a + \underbrace{b+c}_{y}}_{x}. - A label without a brace:
\underset{\text{def}}{=},\overset{!}{=}; labelled arrows\xrightarrow[\text{below}]{\text{above}},\xleftarrow. - Square brackets instead:
\underbracket{a+b}_{\text{sum}}(mathtools).
\documentclass{article}
\usepackage{mathtools} % loads amsmath
\begin{document}
\[
{\underbrace{a + b}_{\text{sum}}} \cdot
\overbrace{x_1 x_2 \cdots x_n}^{n \text{ factors}}
\overset{!}{=} \underbracket{c}_{\text{target}}
\]
\end{document}Horizontal curly braces are the standard way to annotate part of an equation: counting terms, naming a sub-expression or explaining a step. LaTeX has them built in as \underbrace and \overbrace, and amsmath and mathtools add labels, brackets and arrows around them. This guide shows how to label braces, nest and overlap them, keep long labels from stretching the equation, put notes under and over symbols with \underset and \overset, and fix the errors these commands produce.
Underbrace in LaTeX
\underbrace{expression}_{label} draws a brace under the expression and sets the subscript under the brace. It only works in math mode. Use \text (amsmath) for words in the label, and plain math for symbols:
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\[ \underbrace{1 + 1 + \cdots + 1}_{n \text{ times}} = n \]
\[ (a+b)^2 = a^2 + {\underbrace{2ab}_{\text{cross term}}} + b^2 \]
\[ \int_0^1 \underbrace{x^2}_{f(x)} \, dx = \frac{1}{3} \]
Inline it works too: $\underbrace{x + y}_{z}$, but it pushes the lines apart.
\end{document}The label is set in the smaller script size, like any subscript. For a label at full size, write _{\displaystyle ...}, and for an empty brace leave the subscript out. The brace grows with the expression; there is no size to set.
One spacing detail: TeX treats a braced expression as an operator, like \sum, so a + or − right after it loses its space and reads as a sign (“b +c”). Wrap the whole brace in an extra pair of braces, {\underbrace{2ab}_{\text{cross term}}} + b^2, as in the example above, and the normal spacing comes back.
Overbrace in LaTeX
\overbrace{expression}^{label} is the same above the expression, with a superscript for the label. Combining the two annotates one expression from both sides:
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\[ \overbrace{x_1 + x_2 + \cdots + x_n}^{n \text{ terms}} \]
\[ {\overbrace{a + b}^{\text{first}}} + \underbrace{c + d}_{\text{second}} \]
\[ e^{i\pi} + 1 = \overbrace{0}^{\text{zero}} \]
\end{document}Nested and Overlapping Braces
Braces nest without any trick: put one \underbrace inside another. Each inner label sits between the expression and the outer brace:
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\[
\underbrace{a + \underbrace{b + c}_{\text{inner}}}_{\text{outer}}
\qquad
\overbrace{{\underbrace{x + y}_{\text{below}}} + z}^{\text{above}}
\]
\end{document}Overlapping braces, where one brace covers a+b+c and another c+d, need a phantom. Draw the second brace under an invisible copy of the shared part and use \mathrlap (mathtools) so it takes no width:
\documentclass{article}
\usepackage{mathtools}
\begin{document}
\[
{\overbrace{a + b + \mathrlap{\underbrace{\phantom{c + d}}_{y}} c}^{x}} + d
\]
\end{document}Read it from the inside: \phantom{c + d} is empty space as wide as c+d, the underbrace is drawn under that space, and \mathrlap overlaps it with what follows, so the real c and +d print on top of it.
Long Labels: \mathclap and \substack
A label wider than its expression widens the expression, which opens gaps in the equation. \mathclap from mathtools centres the label without letting it take width; \substack from amsmath splits it over lines:
\documentclass{article}
\usepackage{mathtools}
\begin{document}
\[ a + {\underbrace{b}_{\text{a rather long label}}} + c \] % gaps around b
\[ a + {\underbrace{b}_{\mathclap{\text{a rather long label}}}} + c \] % no gaps
\[ f(x) = {\underbrace{x^2}_{\substack{\text{quadratic} \\ \text{term}}}}
+ \underbrace{3x}_{\substack{\text{linear} \\ \text{term}}} \]
\end{document}In align, labels add depth to their line; if two labelled lines come too close, add space after the line break with \\[1ex]. See multiline equations for alignment.
\underset, \overset and Labelled Arrows
When you want a note under or over a single symbol without a brace, use \underset and \overset from amsmath. Extensible arrows with labels come from \xrightarrow and \xleftarrow:
| Command | Result | Package |
|---|---|---|
\underbrace{x}_{a} | Brace under x, label a below | built in |
\overbrace{x}^{a} | Brace over x, label above | built in |
\underset{a}{x} | a set under x, no brace | amsmath |
\overset{a}{x} | a set over x, no brace | amsmath |
\stackrel{a}{=} | a over a relation (older form of \overset) | built in |
\xrightarrow[b]{a} | Arrow that stretches to fit a above, b below | amsmath |
\xleftarrow[b]{a} | The same, pointing left | amsmath |
\underbracket{x}_{a} | Square bracket under x | mathtools |
\overbracket{x}^{a} | Square bracket over x | mathtools |
\underline{x}, \overline{x} | Plain line, no label | built in |
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\[ f(x) \overset{\text{def}}{=} x^2 \qquad
a \underset{\text{(1)}}{\le} b \qquad
x_n \xrightarrow[n \to \infty]{\text{a.s.}} x \qquad
A \xleftarrow{\ f\ } B \]
\[ \lim_{n \to \infty} a_n \qquad \underset{n \to \infty}{\lim} a_n \]
\end{document}For limits under operators such as \lim, \sum or \max, a subscript already goes underneath in display math, so \underset is not needed; see integrals, sums and limits.
\underbracket and \overbracket (mathtools)
mathtools adds square-bracket versions. Two optional arguments set the rule thickness and the height of the bracket ends:
\documentclass{article}
\usepackage{mathtools,xcolor}
\begin{document}
\[ \underbracket{a + b}_{\text{default}} \quad
\underbracket[1pt][6pt]{a + b}_{\text{thick, tall}} \quad
\overbracket{c + d}^{\text{over}} \]
% Coloured brace and label: put the colour inside a group
\[ x = {\color{blue}\underbrace{a + b}_{\text{blue part}}} + c \]
\end{document}For colour, \color inside a group colours the brace, the label and the expression; for more colour options see colors. Vertical curly braces, as in a piecewise function, are a different construction: \left\{ ... \right. or the cases environment, covered in brackets.
Common Errors and Fixes
| Message or symptom | Cause | Fix |
|---|---|---|
| Missing $ inserted | \underbrace or \overbrace used in running text | Wrap it in math: $\underbrace{\text{words}}_{\text{label}}$ |
Undefined control sequence at \text | \text comes from amsmath, which is not loaded | \usepackage{amsmath} (or mathtools, which loads it) |
Undefined control sequence at \underbracket, \mathclap or \mathrlap | These come from mathtools | \usepackage{mathtools} |
| Double subscript | Two labels after one brace: \underbrace{x}_{a}_{b} | One label per brace; stack lines with \substack{a \\ b} |
| Only the first letter of the label is under the brace | Label without braces: \underbrace{x}_sum | Brace the label: _{\text{sum}} |
| Words in the label are italic and run together | Label typed as math: _{the sum} | Use _{\text{the sum}} |
No space in + after a brace (“b +c”) | The brace is an operator, so the next + is read as a sign | Group it: {\underbrace{b}_{x}} + c |
| Big gaps around a short expression | A long label widens it | \mathclap{...} around the label, or \substack |
Frequently Asked Questions
How do I put a brace under an expression in LaTeX?
Use \underbrace in math mode: $\underbrace{a+b+c}_{\text{sum}}$. The brace spans everything in the first pair of braces, and the subscript after it becomes the label under the brace. \text needs the amsmath package; for a math label such as n write _{n}.
How do I put a brace over an expression?
Use \overbrace with a superscript for the label: $\overbrace{x_1 + \dots + x_n}^{n \text{ terms}}$. It works exactly like \underbrace, with the brace and the label above the expression instead of below.
Can I use \underbrace in normal text?
Not directly: \underbrace is a math command, and in running text it stops with “Missing $ inserted”. Wrap it in math mode and put the words in \text: $\underbrace{\text{these words}}_{\text{a label}}$. In a sentence, inline braces push the lines apart, so put larger annotations in a display.
How do I make braces overlap in LaTeX?
Draw one brace normally and the other over an invisible copy of the overlapping part. With mathtools: {\overbrace{a+b+\mathrlap{\underbrace{\phantom{c+d}}_{y}}c}^{x}}+d puts an overbrace over a+b+c and an underbrace under c+d. \mathrlap makes the underbrace take no width, and \phantom gives it the right length.
What is the difference between \underbrace and \underset?
\underbrace draws a horizontal curly brace under an expression and puts the label under the brace. \underset{below}{symbol} places something directly under a symbol with no brace, for example \underset{n \to \infty}{\longrightarrow} or a small note under an equals sign. \overset is the counterpart above.
Why is the space around my underbrace too wide?
A label that is wider than the expression under the brace widens the whole expression. Wrap the label in \mathclap from the mathtools package, \underbrace{x}_{\mathclap{\text{a long label}}}, so it takes no horizontal space. Split long labels over two lines with \substack.
Next Steps
- Mathematical Expressions – Inline and display math with amsmath
- Brackets – Vertical braces, \left and \right, and cases
- Multiline Equations – align, split and labelled steps
- Subscripts and Superscripts – How the labels are placed
- LaTeX Commands and Macros – Define shortcuts for repeated annotations
- Learn LaTeX: Tutorial for Beginners – The basics, from the first document up
Free LaTeX Tools
- LaTeX Preview – Check brace placement with a live PDF preview
- AI LaTeX Generator – Generate annotated equations from text
- LaTeX Symbols Reference – Browse math operators and special characters
Related Articles
Angle Brackets ⟨ ⟩: Symbol, Copy and Paste, and LaTeX
Compile LaTeX from Claude Code or Cursor with the Octree MCP Server
Diameter Symbol (⌀): Meaning, ⌀ vs Ø, and How to Type It on Windows, Mac, Word, LaTeX
LaTeX on iPad: How to Write and Compile LaTeX on a Tablet
Annotate equations faster with AI
Describe the annotation you want and Octree's AI writes the braces, labels and arrows, fixes “Missing $ inserted” and compiles your document in seconds.
Try Octree Free →