Skip to content
Tutorials Center
My learning

Topics

Lesson 13 of 38 ยท Math Typesetting

Matrices, Arrays and Delimiters

Write matrices with pmatrix, bmatrix and vmatrix, build grids with array, define piecewise functions with cases, and size brackets with \left, \right and \big commands.

Matrices, determinants, systems of equations and piecewise functions all share one idea: a grid of math cells, separated by & within a row and \\ between rows. Once you know that, every one of them is a one-line change of environment. This lesson also covers delimiters (parentheses, brackets, bars) and how to make them grow with the content.

The matrix environments

With amsmath, each matrix environment fixes the bracket style for you.

Environment Brackets Example use
matrix none Bare grid
pmatrix round ( ) The usual matrix
bmatrix square [ ] Matrices in many textbooks
Bmatrix braces { } Rare
vmatrix single vertical bars Determinants
Vmatrix double bars โ€– โ€– Norms
LATEX
\[
  A = \begin{pmatrix}
        1 & 2 & 3 \\
        4 & 5 & 6
      \end{pmatrix}
\qquad
  \det B = \begin{vmatrix} a & b \\ c & d \end{vmatrix} = ad - bc
\]

Rules to remember:

  • Cells in a row are separated by &; rows end with \\ (no \\ needed after the last row).
  • All rows should have the same number of cells; if one is short, the remaining cells stay empty.
  • Spaces and line breaks in the source are for you; the compiler ignores them. Align the & characters in your source so you can see the grid.
  • Matrices inside text use smallmatrix, drawn small to fit a line: $\left(\begin{smallmatrix} a & b \\ c & d \end{smallmatrix}\right)$. In real LaTeX, the brackets must be added by you or by psmallmatrix from mathtools.

Dots help show large matrices. Use \cdots, \vdots and \ddots in cells:

LATEX
\[
  \begin{bmatrix}
    a_{11} & \cdots & a_{1n} \\
    \vdots & \ddots & \vdots \\
    a_{m1} & \cdots & a_{mn}
  \end{bmatrix}
\]

The array environment

array is the general version: you choose column alignment and any delimiters yourself. The argument lists one letter per column: l, c or r for left, centered or right alignment. A | between letters draws a vertical rule, and \hline a horizontal one.

LATEX
\[
  \left[\begin{array}{cc|c}
     1 & 2 & 3 \\
     4 & 5 & 6
  \end{array}\right]
\]

This is an augmented matrix with a vertical bar before the last column, a case bmatrix cannot do. The \left[ and \right] around the array supply the brackets (explained below). Arrays also serve for small tables in math, such as a truth table; for ordinary tables use tabular.

Piecewise functions with cases

cases aligns branches and draws a big left brace.

LATEX
\[
  |x| = \begin{cases}
          x  & \text{if } x \ge 0, \\
          -x & \text{if } x < 0.
        \end{cases}
\]

The left column is the value and the right column is the condition, set in text mode where needed (use \text). The same pattern works for any definition by cases.

Systems of equations

For several aligned equations use aligned or align (the next lesson). For a system with a brace on the left, combine them:

LATEX
\[
  \left\{ \begin{aligned}
    2x + y &= 5 \\
     x - y &= 1
  \end{aligned} \right.
\]

Notice \right.: every \left needs a matching \right. A dot means "no visible delimiter on this side."

Delimiters that grow

Parentheses typed as plain ( and ) stay the same size, so around a fraction they look squashed. Put \left and \right in front to make them as tall as their content.

LATEX
\[ \left( \frac{a+b}{c} \right)^2 \qquad
   \left[ \sum_{k=1}^{n} k \right] \qquad
   \left\lvert \frac{x}{y} \right\rvert \qquad
   \left\langle u, v \right\rangle \]
  • Delimiters pair up as a group: \left ... \right, with no line break allowed between them (a displayed formula that is too long should be split with align first).
  • Use \left. or \right. when you need only one side.
  • \middle| places a delimiter inside, as in \left\{ x \;\middle|\; x > 0 \right\}.
  • Common delimiters: ( ), [ ], \{ \}, \langle \rangle, \lvert \rvert, \lVert \rVert, \lfloor \rfloor, \lceil \rceil, \uparrow.

When \left and \right produce too much space, or you need exactly one size, use the manual sizes:

LATEX
\bigl( \bigr)   \Bigl( \Bigr)   \biggl( \biggr)   \Biggl( \Biggr)

Small, medium, large, extra large: \bigl for the left side and \bigr for the right. These do not require pairing, which helps with a bracket that opens in one line of an alignment and closes in another.

Try it

Modify the grids, brackets and cases below, one formula per line. Each line of the box is one formula, so matrices are written on a single line using \\ for rows.

Matrices, cases and delimiters (KaTeX)

Practical tips

  • Keep the same style across a document: choose pmatrix or bmatrix and stick with it.
  • Use a subscript with a comma for multi-index entries: a_{ij}, a_{i,j+1}.
  • For very wide matrices, reduce the column gap with \setlength{\arraycolsep}{3pt}.
  • Vectors are matrices with one column, or written inline with \mathbf{v} or \vec{v}.
  • A forgotten \right gives "Missing \right. inserted". A & outside an alignment environment gives "Misplaced alignment tab character &".

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which environment gives a determinant with vertical bars?

    vmatrix draws single vertical bars; Vmatrix draws double bars.
  2. 2. In a matrix, what separates cells in a row and rows from each other?

    & separates columns and \ ends a row.
  3. 3. What is \right. for?

    A \left needs a matching \right; the dot means no delimiter is drawn.
  4. 4. What should you use for a piecewise function with conditions?

    cases aligns values and conditions and draws a left brace.

Summary

  • Matrix environments use & for columns and \\ for rows; choose pmatrix, bmatrix or vmatrix for the brackets.
  • array gives full control over alignment and vertical rules (augmented matrices).
  • cases builds piecewise definitions.
  • \left and \right size delimiters automatically; \bigl to \Biggr set manual sizes; \right. is an empty delimiter.

Next: Aligning and Numbering Equations