Matrices in LaTeX use the environments from amsmath. For example, pmatrix draws a matrix in parentheses. Columns are separated with &, and rows end with \\. A determinant is written either with the vmatrix environment, which draws vertical bars, or with the \det operator.
Matrix environments
Load amsmath in the preamble. Each environment draws a different set of delimiters:
| Environment | Delimiters |
|---|---|
matrix |
none |
pmatrix |
parentheses ( ) |
bmatrix |
square brackets [ ] |
Bmatrix |
curly braces { } |
vmatrix |
single vertical bars |
Vmatrix |
double vertical bars |
smallmatrix |
none, sized for inline text |
Write a matrix step by step
\[
A =
\begin{pmatrix}
a_{11} & a_{12} & a_{13} \\
a_{21} & a_{22} & a_{23} \\
a_{31} & a_{32} & a_{33}
\end{pmatrix}
\]
&moves to the next column.\\ends a row. Leave it off the last row.- Subscripts such as
a_{11}need braces when they have more than one character. The subscript guide explains why.
Dots and larger matrices
Use \cdots for horizontal dots, \vdots for vertical dots, and \ddots for diagonal dots:
\[
I_n =
\begin{bmatrix}
1 & 0 & \cdots & 0 \\
0 & 1 & \cdots & 0 \\
\vdots & \vdots & \ddots & \vdots \\
0 & 0 & \cdots & 1
\end{bmatrix}
\]
This is the n by n identity matrix.
Determinants
Use vmatrix to write a determinant in full:
\[
\begin{vmatrix}
a & b \\
c & d
\end{vmatrix}
= ad - bc
\]
The \det operator is built into LaTeX and prints “det” in upright type. If $A$ is the 2 by 2 matrix with rows $(a, b)$ and $(c, d)$, write its determinant as:
\[
\det(A) = ad - bc
\]
Solving a determinant
For a 2 by 2 matrix, the determinant is $ad - bc$. For a 3 by 3 matrix, one common method is expansion along the first row. Each term multiplies an entry of the first row by the determinant of the smaller 2 by 2 matrix that remains after removing that entry’s row and column:
\[
\det(A) =
\begin{vmatrix}
a & b & c \\
d & e & f \\
g & h & i
\end{vmatrix}
= a(ei - fh) - b(di - fg) + c(dh - eg)
\]
Matrices in running text
Use smallmatrix in inline math so the rows stay compact:
The matrix $\begin{smallmatrix} a & b \\ c & d \end{smallmatrix}$ has determinant $ad - bc$.
For a delimiter pair that no environment provides, wrap a matrix in \left and \right, as described in the bracket sizing guide.
Numbering a matrix equation
To number a matrix equation, wrap it in an equation environment and add a \label. How to label an equation shows how to cite it in the text.
Common errors
- Undefined control sequence for
pmatrixorvmatrix:amsmathis not loaded. - Misplaced alignment tab character &: an
&appears outside a matrix,alignor table environment. - Ragged rows: a row with more
&characters than the others adds an extra column and shifts the layout. Count the&characters in each row. \detoutside math mode: the operator needs math mode, so wrap it in$...$or\[...\].