LaTeX Guide

LaTeX Matrices

Six environments for six bracket styles. & separates columns, \\ separates rows. Always inside math mode.

The basic pattern

\usepackage{amsmath}

% 2x2 matrix with parentheses
$\begin{pmatrix}
  a & b \\
  c & d
\end{pmatrix}$

% 3x3 with square brackets
$\begin{bmatrix}
  1 & 2 & 3 \\
  4 & 5 & 6 \\
  7 & 8 & 9
\end{bmatrix}$

% Determinant
$\begin{vmatrix}
  a & b \\
  c & d
\end{vmatrix} = ad - bc$

The seven matrix environments

EnvironmentBrackets / use
matrixNo brackets — bare matrix
pmatrix( ) parentheses
bmatrix[ ] square brackets
Bmatrix{ } curly braces
vmatrix| | single bars (determinant)
Vmatrix‖ ‖ double bars (norm)
smallmatrixInline-sized matrix for cramped spaces

Column vector and row vector

% Column vector
$\mathbf{v} = \begin{pmatrix} x \\ y \\ z \end{pmatrix}$

% Row vector
$\mathbf{v}^T = \begin{pmatrix} x & y & z \end{pmatrix}$

Matrix with ellipsis (general n×n)

$A = \begin{pmatrix}
  a_{11} & a_{12} & \dots  & a_{1n} \\
  a_{21} & a_{22} & \dots  & a_{2n} \\
  \vdots & \vdots & \ddots & \vdots \\
  a_{m1} & a_{m2} & \dots  & a_{mn}
\end{pmatrix}$

Right-aligned matrix entries

% Right-align — useful when entries have negative signs
$\begin{pmatrix*}[r]
  -1 & 2 \\
   3 & -4
\end{pmatrix*}$

Inline small matrix

The matrix $\bigl(\begin{smallmatrix} a & b \\ c & d \end{smallmatrix}\bigr)$
fits inline without breaking the line height.

Common mistakes

  • Forgetting \usepackage{amsmath}. All matrix environments need it.
  • Inconsistent column count. Each row needs the same number of & separators.
  • Missing math mode. Wrap in $ ... $ or use a display environment.
  • Trailing \\ on the last row. Sometimes causes errors — try removing it if you get a complaint.
Typst matrices: one function
$ mat(a, b; c, d) $              // square brackets default
$ mat(delim: "(", a, b; c, d) $   // parens
$ mat(delim: "|", a, b; c, d) $   // determinant

One mat() function with a delimiter argument. Try TypeTeX free.

Try TypeTeX free

Frequently Asked Questions

How do I make a matrix in LaTeX?

Use the pmatrix environment from amsmath: \begin{pmatrix} a & b \\ c & d \end{pmatrix} produces a 2x2 matrix in parentheses. Columns are separated by &, rows by \\. Always inside math mode ($ ... $ or display).

What's the difference between pmatrix, bmatrix, and vmatrix?

Just the brackets: pmatrix uses parentheses (), bmatrix uses square brackets [], Bmatrix uses curly braces {}, vmatrix uses single vertical bars | | (used for determinants), Vmatrix uses double vertical bars ‖ ‖ (used for norms). The contents and syntax are identical.

How do I write a determinant in LaTeX?

Use vmatrix: \begin{vmatrix} a & b \\ c & d \end{vmatrix} renders as |a b; c d| with single vertical bars indicating the determinant. Or write it as \det\begin{pmatrix} a & b \\ c & d \end{pmatrix} for an explicit 'det' label.

How do I make a column vector?

Use pmatrix or bmatrix with one column: \begin{pmatrix} x \\ y \\ z \end{pmatrix}. Rows are separated by \\. For a row vector, write it as a 1xN matrix: \begin{pmatrix} x & y & z \end{pmatrix}.

How do I align matrix columns left or right?

Use matrix* (or pmatrix*, bmatrix*, etc.) with a column-alignment argument: \begin{pmatrix*}[r] -1 & 2 \\ 3 & -4 \end{pmatrix*} right-aligns negative numbers cleanly. Use [l] for left, [c] for center (default).

How do I add an ellipsis (...) in a matrix?

\dots for horizontal, \vdots for vertical (top to bottom), \ddots for diagonal (top-left to bottom-right). Common in theory papers: \begin{pmatrix} a_{11} & \dots & a_{1n} \\ \vdots & \ddots & \vdots \\ a_{m1} & \dots & a_{mn} \end{pmatrix}.

How do I write a block matrix or partitioned matrix?

Use \begin{pmatrix*}[c|c] for vertical partition with a separator. The pipe character | adds a vertical line. For more flexibility, use \begin{array}{c|c c} ... \end{array} wrapped in \left( ... \right). The blkarray package handles complex block layouts.

How do I make a small inline matrix?

Use smallmatrix: $\bigl( \begin{smallmatrix} a & b \\ c & d \end{smallmatrix} \bigr)$. The \bigl( \bigr) provides the parentheses since smallmatrix doesn't include them. Useful when matrices appear inline in body text.

Why doesn't my matrix compile?

Three common causes: (1) missing \usepackage{amsmath}; (2) using a literal | for vmatrix instead of the environment; (3) inconsistent column counts (one row has more & than another). Check the column count is uniform across all rows.

More LaTeX guides