Tx · LaTeX & TikZ

How to Put an Underbrace in a LaTeX Matrix

Published By the 9to5Science editorial team

At a glance

  1. 1. Stay in math mode

    Use an underbrace inside a matrix cell; matrix environments already put their contents in math mode.

  2. 2. Write the brace

    Put the expression in the first argument of \underbrace and its annotation in the subscript.

  3. 3. Check the label

    Use \text{...} for words, and compile with the amsmath package loaded.

To put an underbrace in a LaTeX matrix, write \underbrace{...}_{...} inside the matrix cell you want to annotate. The expression goes in braces after \underbrace; the annotation goes in the subscript, after the underscore. Matrix environments are already in math mode, so do not wrap individual cells in $...$.

Basic syntax

The general form is:

\underbrace{expression}_{annotation}

For a short mathematical annotation, write it directly, such as \underbrace{x+y}_{2}. For words, use \text{...}: \underbrace{x+y}_{\text{two terms}}. The \text command is provided by amsmath and keeps the label in a text-style font rather than typesetting it as a string of italic mathematical variables.

Here is a complete, minimal example:

\documentclass{article}
\usepackage{amsmath}

\begin{document}

\[
A = \begin{bmatrix}
  x_1 & \underbrace{a+b}_{\text{two terms}} & 0 \\
  0   & y                              & \underbrace{c+d+e}_{\text{three terms}}
\end{bmatrix}
\]

\end{document}

This produces a matrix with a brace beneath a+b in the first row and beneath c+d+e in the second. The bmatrix environment supplies square brackets; use pmatrix for parentheses or matrix for no surrounding delimiters. These environments come from amsmath.

What each part does

In \underbrace{a+b}_{\text{two terms}}, a+b is the material covered by the brace. The underscore introduces the annotation placed underneath it. TeX sizes the brace to fit the material automatically.

The & characters separate matrix columns, and \\ ends a row. Keep the underbrace expression together in a single cell unless you deliberately construct a nested matrix or array. For example, in a & \underbrace{b+c}_{\text{sum}}, the brace belongs to the second cell; it does not cover entries on both sides of &.

Annotating a block of entries

A matrix is arranged in alignment cells, so a brace cannot simply stretch across neighboring cells by writing \underbrace around text that includes a column separator. If you need to mark a rectangular block as one object, put a smaller matrix inside a cell and brace that nested matrix:

\[
M = \begin{bmatrix}
  \underbrace{\begin{matrix} a & b \\ c & d \end{matrix}}_{\text{block}}
    & e \\
  f & g
\end{bmatrix}
\]

Here the inner matrix is one entry of the outer matrix, and its four entries are grouped under a single brace. This is useful when the block itself is the object you want to name. For a brace that should indicate a subset of columns or rows without changing the matrix entries, a diagram or a separate annotation may be clearer than nesting matrices.

Common mistakes

  • Putting the annotation in the wrong place. Use _{...} for a label below the underbrace. The corresponding overbrace form is \overbrace{...}^{...}.
  • Adding dollar signs inside a matrix. The matrix environment is already in math mode. Extra $ signs inside a cell can cause errors.
  • Writing words as math variables. Without \text, a label such as number of terms is treated as separate mathematical symbols, with unwanted spacing and italics. Use \text{number of terms}.
  • Expecting a brace to cross an alignment separator. An & divides cells; it is not part of the expression being braced. Group a block in a nested matrix if that is the intended object.
  • Forgetting the package. Environments such as bmatrix and the \text command require \usepackage{amsmath}.

For a compact annotation within one entry, the basic \underbrace{...}_{...} form is usually all you need. Use a nested matrix only when the entire block should be treated as one grouped expression.

References

  1. The amsmath package documentation

Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.