Matrices in LaTeX
A matrix is a rectangular array of entries; in LaTeX the amsmath matrix environments lay it out, using & to separate columns and \\ to end each row.
LaTeX command
\begin{pmatrix} a & b \\ c & d \end{pmatrix}Not the symbol you meant? Draw it to find the command →
The workhorse is \begin{pmatrix} ... \end{pmatrix}, which wraps the array in round brackets. Inside, & separates the entries in a row and \\ starts a new row, so \begin{pmatrix} 1 & 0 \\ 0 & 1 \end{pmatrix} is a 2x2 identity. The matrix family is provided by amsmath and is fully supported by KaTeX.
The bracket style is chosen by the environment name: pmatrix gives parentheses, bmatrix square brackets, Bmatrix curly braces, vmatrix single vertical bars (a determinant) and Vmatrix double bars (a norm). The plain matrix environment draws no fence at all, which is handy when you want to add your own with \left and \right.
When you need custom column alignment or a vertical rule, such as an augmented matrix, fall back to the array environment inside \left[ ... \right]. The column specifier cc|c sets two centred columns, a rule, then a third centred column. array is core LaTeX and does not need amsmath.
Other forms
\begin{bmatrix}...\end{bmatrix}square brackets\begin{vmatrix}...\end{vmatrix}determinant barsExamples
$\begin{pmatrix} 1 & 0 \\ 0 & 1 \end{pmatrix}$a 2x2 identity in round brackets
$\begin{bmatrix} a & b \\ c & d \end{bmatrix}$the same shape with square brackets
$\begin{vmatrix} a & b \\ c & d \end{vmatrix} = ad - bc$vertical bars denote a determinant
$\left[\begin{array}{cc|c} 1 & 0 & 5 \\ 0 & 1 & 6 \end{array}\right]$an augmented matrix built with array
$$\begin{pmatrix} a_{11} & \cdots & a_{1n} \\ \vdots & \ddots & \vdots \\ a_{m1} & \cdots & a_{mn} \end{pmatrix}$$a general matrix using \cdots, \vdots and \ddots
Tips and common mistakes
- The pmatrix, bmatrix, vmatrix family needs amsmath. A bare document without it will not compile.
- Remember the mnemonic: p is parentheses, b is brackets, B is braces, v is vertical bars (determinant), V is double bars (norm).
- Do not add \\ after the final row; the trailing break can create a spurious empty row.
- For a vertical rule or per-column alignment, use array with a column spec such as {cc|c}; the matrix environments do not allow rules.
- Keep the number of & entries consistent across rows, or the columns will misalign.
Working from handwritten notes?
LatexNotes turns a photo or PDF of handwritten mathematics into clean, compilable LaTeX - graphs and all. Free to try, no sign-up.
Convert your maths to LaTeX →FAQ
How do I write a determinant in LaTeX?
Use the vmatrix environment, which surrounds the array with single vertical bars: \begin{vmatrix} a & b \\ c & d \end{vmatrix}.
How do I make an augmented matrix?
Use \left[\begin{array}{cc|c} ... \end{array}\right]. The | in the column specifier draws the vertical rule separating coefficients from the constants.
What is the difference between pmatrix and bmatrix?
They differ only in the enclosing fence: pmatrix uses round parentheses, bmatrix uses square brackets. The entry syntax is identical.