How to Write a Matrix in LaTeX
To write a matrix in LaTeX, load amsmath and use pmatrix for round brackets or bmatrix for square ones, in math mode. Separate the entries in a row with & and end each row with \\.
\[ A = \begin{pmatrix} 1 & 2 \\ 3 & 4 \end{pmatrix} \]Needs \usepackage{amsmath} in the preamble.
Full document you can compile
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\[ A = \begin{pmatrix} 1 & 2 \\ 3 & 4 \end{pmatrix} \]
\end{document}Which bracket does each environment give?
The first letter sets the delimiter: matrix has none, pmatrix parentheses, bmatrix square brackets, Bmatrix braces, vmatrix single bars for a determinant and Vmatrix double bars for a norm.
\[
\begin{matrix} a & b \\ c & d \end{matrix} \quad
\begin{pmatrix} a & b \\ c & d \end{pmatrix} \quad
\begin{bmatrix} a & b \\ c & d \end{bmatrix} \quad
\begin{Bmatrix} a & b \\ c & d \end{Bmatrix} \quad
\begin{vmatrix} a & b \\ c & d \end{vmatrix} \quad
\begin{Vmatrix} a & b \\ c & d \end{Vmatrix}
\]Needs \usepackage{amsmath} in the preamble.
Full document you can compile
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\[
\begin{matrix} a & b \\ c & d \end{matrix} \quad
\begin{pmatrix} a & b \\ c & d \end{pmatrix} \quad
\begin{bmatrix} a & b \\ c & d \end{bmatrix} \quad
\begin{Bmatrix} a & b \\ c & d \end{Bmatrix} \quad
\begin{vmatrix} a & b \\ c & d \end{vmatrix} \quad
\begin{Vmatrix} a & b \\ c & d \end{Vmatrix}
\]
\end{document}How do you write a large matrix in LaTeX with dots?
Use \cdots for horizontal dots, \vdots for vertical dots and \ddots for diagonal dots, each in its own cell. Entries with two indices need braces: a_{mn}.
\[ A = \begin{bmatrix}
a_{11} & a_{12} & \cdots & a_{1n} \\
a_{21} & a_{22} & \cdots & a_{2n} \\
\vdots & \vdots & \ddots & \vdots \\
a_{m1} & a_{m2} & \cdots & a_{mn}
\end{bmatrix} \]Needs \usepackage{amsmath} in the preamble.
Full document you can compile
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\[ A = \begin{bmatrix}
a_{11} & a_{12} & \cdots & a_{1n} \\
a_{21} & a_{22} & \cdots & a_{2n} \\
\vdots & \vdots & \ddots & \vdots \\
a_{m1} & a_{m2} & \cdots & a_{mn}
\end{bmatrix} \]
\end{document}Why does a wide matrix give "Extra alignment tab"?
The amsmath matrix environments allow 10 columns by default. An 11th & stops the compile with ! Extra alignment tab has been changed to \cr. Raise the limit in the preamble with \setcounter{MaxMatrixCols}{20}.
How do you write an augmented matrix?
The matrix environments can't draw a vertical line, so use array with a | in the column list, and add the brackets with \left[ and \right].
\[ \left[\begin{array}{cc|c}
1 & 2 & 5 \\
3 & 4 & 6
\end{array}\right] \]Needs \usepackage{amsmath} in the preamble.
Full document you can compile
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\[ \left[\begin{array}{cc|c}
1 & 2 & 5 \\
3 & 4 & 6
\end{array}\right] \]
\end{document}How do you put a small matrix in a line of text?
smallmatrix sets the entries in a smaller size so the matrix doesn't spread the lines apart. It has no brackets of its own; add them with \left( and \right).
The vector $\left(\begin{smallmatrix} x \\ y \end{smallmatrix}\right)$ fits in a line of text,
and so does $I = \left(\begin{smallmatrix} 1 & 0 \\ 0 & 1 \end{smallmatrix}\right)$.Needs \usepackage{amsmath} in the preamble.
Full document you can compile
\documentclass{article}
\usepackage{amsmath}
\begin{document}
The vector $\left(\begin{smallmatrix} x \\ y \end{smallmatrix}\right)$ fits in a line of text,
and so does $I = \left(\begin{smallmatrix} 1 & 0 \\ 0 & 1 \end{smallmatrix}\right)$.
\end{document}Is there an easier way to type a matrix?
The equation editor has matrix templates with a live preview. For a grid of data rather than math, use a table instead. The online LaTeX converter turns each matrix environment into MathML.
Sources
- User’s Guide for the amsmath Package (CTAN), read Nov 28, 2026
- LaTeX2e: An unofficial reference manual, array, read Nov 28, 2026
Text drafted with AI from the amsmath documentation; every example compiled with TeX Live 2026; checked by Cem Demir. See the editorial policy.