Getting Started
Text Formatting
Mathematical Expressions
Document Structure
Page Layout
Accessibility
Errors & Troubleshooting
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:
matrix Environment (no delimiters)
pmatrix Environment (parentheses)
bmatrix Environment (square brackets)
vmatrix Environment (vertical bars — determinants)
Bmatrix Environment (curly braces)
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.
Quick Tools for Creating LaTeX Matrices
Need to create a matrix quickly?
Use our Matrix Generator to instantly create various types of matrices including identity, diagonal, and custom matrices with different delimiters.
Open Matrix Generator
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.
Every \left needs a matching \right, even when one side is invisible. Use \right. — with the dot — for a one-sided delimiter.
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\cdotsfor professional-looking ellipses
Remember to include \usepackage{amsmath} in your document preamble to access these matrix environments.
Related reading: the align environment for multi-line equations and writing vectors in LaTeX.
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:
matrix Environment (no delimiters)
pmatrix Environment (parentheses)
bmatrix Environment (square brackets)
vmatrix Environment (vertical bars — determinants)
Bmatrix Environment (curly braces)
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.
Quick Tools for Creating LaTeX Matrices
Need to create a matrix quickly?
Use our Matrix Generator to instantly create various types of matrices including identity, diagonal, and custom matrices with different delimiters.
Open Matrix Generator
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.
Every \left needs a matching \right, even when one side is invisible. Use \right. — with the dot — for a one-sided delimiter.
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\cdotsfor professional-looking ellipses
Remember to include \usepackage{amsmath} in your document preamble to access these matrix environments.
Related reading: the align environment for multi-line equations and writing vectors in LaTeX.
Getting Started
Text Formatting
Mathematical Expressions
Document Structure
Page Layout
Accessibility
Errors & Troubleshooting
