Underleaf Logo
Underleaf
Blog
Log InTry Free

Learn LaTeX

Getting Started

  • What is LaTeX?
  • LaTeX for Beginners

Matrices and Arrays in LaTeX

LaTeX provides several environments for creating matrices and arrays. This guide covers the different types of matrices, their syntax, and advanced formatting options.

Basic Matrix Types

LaTeX offers various matrix environments, each with different delimiters:

  1. matrix Environment (no delimiters)

  2. pmatrix Environment (parentheses)

  3. bmatrix Environment (square brackets)

  4. vmatrix Environment (vertical bars — determinants)

  5. Bmatrix Environment (curly braces)

  6. Vmatrix Environment (double bars — norms)

The naming is consistent: the letter before matrix tells you the delimiter. Lowercase gives you the ordinary bracket (pmatrix → parentheses, vmatrix → single bars) and uppercase gives you the “bigger” variant (Bmatrix → braces, Vmatrix → double bars).

Inside all of them, & separates columns and \\ ends a row. There is no \\ after the final row — adding one creates an empty trailing row, which shows up as unexpected vertical space inside the brackets.

Matrix with Alignment

You can control column alignment using the array environment:

The {lcr} specifies left, center, and right alignment for each column.

Augmented Matrices

For systems of equations, you can create augmented matrices using the array environment:

The vertical line in {cc|c} creates the augmentation line.

Inline Matrices with smallmatrix

A full matrix environment inside a sentence pushes the surrounding lines apart. Use smallmatrix instead — it typesets at script size and leaves line spacing intact, so it sits inline in a sentence like $\left(\begin{smallmatrix} 0 & -1 \\ 1 & 0 \end{smallmatrix}\right)$:

smallmatrix draws no delimiters of its own, so wrap it in \left( and \right) yourself.

Multiplying Matrices

The product of an m × n matrix and an n × r matrix is defined entry by entry as a sum over the shared dimension:

Written out, the intermediate sums are worth keeping visible while you check the arithmetic:

Three Errors That Break Most Matrices

Missing $ inserted

Matrix environments only work in math mode. Writing \begin{bmatrix} in ordinary text produces this error. Wrap it in \[ ... \] for a displayed matrix or $ ... $ for an inline one.

Extra alignment tab has been changed to \cr

A row has more & separators than the matrix has columns — usually one stray & at the end of a row. A three-column matrix needs exactly two separators per row.

Brackets that do not stretch

If your delimiters are the wrong height you have probably typed literal [ and ] characters. Either use the matching environment (bmatrix) or pair \left[ with \right] so LaTeX sizes them to the content.

Advanced Matrix Features

  • Dots in Matrices

  • Nested Matrices

  • Matrix with Text

Best Practices

  • Use \begin{array} when you need precise control over column alignment
  • Use \begin{pmatrix} or \begin{bmatrix} for standard matrices
  • Use \begin{smallmatrix} for inline matrices to maintain proper line spacing
  • Use \vdots, \ddots, and \cdots for professional-looking ellipses

Related reading: the align environment for multi-line equations and writing vectors in LaTeX.

Try it free

Skip the syntax — let AI write it.

Snap a photo of an equation, a table, or full handwritten notes and Underleaf turns it into clean, compilable LaTeX in seconds. 10 free credits every month, no credit card required.

Convert your page
Handwritten notes converted into a typeset LaTeX document

Matrices and Arrays in LaTeX

LaTeX provides several environments for creating matrices and arrays. This guide covers the different types of matrices, their syntax, and advanced formatting options.

Basic Matrix Types

LaTeX offers various matrix environments, each with different delimiters:

  1. matrix Environment (no delimiters)

  2. pmatrix Environment (parentheses)

  3. bmatrix Environment (square brackets)

  4. vmatrix Environment (vertical bars — determinants)

  5. Bmatrix Environment (curly braces)

  6. Vmatrix Environment (double bars — norms)

The naming is consistent: the letter before matrix tells you the delimiter. Lowercase gives you the ordinary bracket (pmatrix → parentheses, vmatrix → single bars) and uppercase gives you the “bigger” variant (Bmatrix → braces, Vmatrix → double bars).

Inside all of them, & separates columns and \\ ends a row. There is no \\ after the final row — adding one creates an empty trailing row, which shows up as unexpected vertical space inside the brackets.

Matrix with Alignment

You can control column alignment using the array environment:

The {lcr} specifies left, center, and right alignment for each column.

Augmented Matrices

For systems of equations, you can create augmented matrices using the array environment:

The vertical line in {cc|c} creates the augmentation line.

Inline Matrices with smallmatrix

A full matrix environment inside a sentence pushes the surrounding lines apart. Use smallmatrix instead — it typesets at script size and leaves line spacing intact, so it sits inline in a sentence like $\left(\begin{smallmatrix} 0 & -1 \\ 1 & 0 \end{smallmatrix}\right)$:

smallmatrix draws no delimiters of its own, so wrap it in \left( and \right) yourself.

Multiplying Matrices

The product of an m × n matrix and an n × r matrix is defined entry by entry as a sum over the shared dimension:

Written out, the intermediate sums are worth keeping visible while you check the arithmetic:

Three Errors That Break Most Matrices

Missing $ inserted

Matrix environments only work in math mode. Writing \begin{bmatrix} in ordinary text produces this error. Wrap it in \[ ... \] for a displayed matrix or $ ... $ for an inline one.

Extra alignment tab has been changed to \cr

A row has more & separators than the matrix has columns — usually one stray & at the end of a row. A three-column matrix needs exactly two separators per row.

Brackets that do not stretch

If your delimiters are the wrong height you have probably typed literal [ and ] characters. Either use the matching environment (bmatrix) or pair \left[ with \right] so LaTeX sizes them to the content.

Advanced Matrix Features

  • Dots in Matrices

  • Nested Matrices

  • Matrix with Text

Best Practices

  • Use \begin{array} when you need precise control over column alignment
  • Use \begin{pmatrix} or \begin{bmatrix} for standard matrices
  • Use \begin{smallmatrix} for inline matrices to maintain proper line spacing
  • Use \vdots, \ddots, and \cdots for professional-looking ellipses

Related reading: the align environment for multi-line equations and writing vectors in LaTeX.

Underleaf Logo
Underleaf

Practical tools for academic writing, document conversion, and research workflows.

Go to appContact us

Company

PricingBlogTutorialsConference TemplatesConference Deadlines

Free Tools

Image to LaTeXExcel to LaTeXArXiv to LaTeXTikZ GeneratorLaTeX Table GeneratorCitation GeneratorThesis GeneratorChrome ExtensionAll Tools

Ask AI about Underleaf

Ask ChatGPTAsk ClaudeAsk Perplexity

© 2026 Underleaf. All rights reserved.