Write parenthesized matrices in LaTeX with pmatrix.
Load amsmath in your preamble and place \begin{pmatrix} inside math mode. Use & to separate columns and \\ to break rows, leaving off the trailing backslashes on the final line to prevent phantom padding.
The short answer: put \usepackage{amsmath} in your preamble, then write your matrix inside math delimiters using \begin{pmatrix} and \end{pmatrix}. For inline text, swap to psmallmatrix from mathtools so your document maintains even line spacing.
Basic syntax and minimal preamble
Standard LaTeX has no built-in pmatrix environment. The American Mathematical Society package provides it.
To typeset a matrix enclosed by round parentheses, load amsmath in the preamble. The matrix must sit inside math mode, such as an unnumbered display math block \[ ... \] or a numbered equation environment.
Entries within each row are separated by an ampersand &. A double backslash \\ ends each row. A frequent mistake is placing \\ after the final row; doing so instructs the compiler to add an empty row, creating lopsided vertical padding inside the parentheses.
The six standard matrix delimiters in amsmath
The amsmath package defines six matrix environments. Their inner syntax is identical; only the surrounding delimiters change.
Ellipses for arbitrary and large dimensions
When representing an m by n matrix, use dots to signify continuing patterns across rows, columns and diagonals.
Horizontal, vertical and diagonal dots
Use
\cdotsfor horizontal dots along rows,\vdotsfor vertical dots down columns, and\ddotsfor diagonal continuation from top-left to bottom-right.\[ \begin{pmatrix} 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{pmatrix} \]Identity matrices with recurring zeros
Combine diagonal dots with explicit diagonal values to show structured square matrices without writing every zero entry.
\[ I_n = \begin{pmatrix} 1 & 0 & \cdots & 0 \\ 0 & 1 & \cdots & 0 \\ \vdots & \vdots & \ddots & \vdots \\ 0 & 0 & \cdots & 1 \end{pmatrix} \]
Inline matrices without uneven line heights
Placing a regular pmatrix inside running text distorts the paragraph because full-sized matrices push lines apart.
Column alignment and the 10-column limit
By default, amsmath centers every column entry and caps the total column count at ten.
Right-align negative numbers with mathtools
Centered columns make matrices with mixed minus signs look untidy because negative symbols push numbers out of vertical alignment. Use
pmatrix*frommathtoolswith the[r]optional argument to right-align values.\usepackage{mathtools} ... \[ \begin{pmatrix*}[r] 12 & -3 \\ -4 & 105 \end{pmatrix*} \]Raise the MaxMatrixCols counter
If your matrix contains more than ten columns, compilation halts with the error 'Extra alignment tab has been changed to \cr'. LaTeX limits matrix width to protect memory. Raise the counter in your preamble or right before the equation.
\setcounter{MaxMatrixCols}{20} \[ \begin{pmatrix} 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 \end{pmatrix} \]
Augmented matrices with vertical partition lines
Standard pmatrix environments do not accept column format specifications like | for partitioning systems of linear equations.
| Approach | Syntax mechanism | Pros | Cons |
|---|---|---|---|
| array with \left( and \right) | \left(\begin{array}{cc|c} ... \end{array}\right) | Standard LaTeX, no extra packages | More verbose syntax |
| pmatrix with redefined column spec | \makeatletter ... \makeatother preamble patch | Keeps the pmatrix environment name | Preamble clutter, harder to share |
Fixing common pmatrix errors
Most matrix compilation errors in Overleaf, Texeno or local TeX installations stem from three common syntax traps.
LaTeX Error: Environment pmatrix undefined
You forgot to include
\usepackage{amsmath}in your preamble. Add it before\begin{document}. If you need right-alignment stars likepmatrix*, loadmathtoolsinstead.\documentclass{article} \usepackage{amsmath} \begin{document} \[ \begin{pmatrix} 1 & 0 \\ 0 & 1 \end{pmatrix} \] \end{document}Missing $ inserted
Matrix environments belong exclusively to math mode. If you invoke
\begin{pmatrix}in regular text without wrapping it in\[ ... \]or$...$, TeX halts with a missing math delimiter warning.% Wrong: % \begin{pmatrix} 1 & 2 \\ 3 & 4 \end{pmatrix} % Right: \[ \begin{pmatrix} 1 & 2 \\ 3 & 4 \end{pmatrix} \]Extra alignment tab has been changed to \cr
This indicates either an extra
&in a row, a stray before the newline, or exceeding the default 10-column ceiling. Check your column count against .
Questions
What package do I need for pmatrix in LaTeX?
You need the amsmath package. Add \usepackage{amsmath} to your document preamble before \begin{document}.
What is the difference between pmatrix and bmatrix?
The delimiter shape is the only difference. pmatrix encloses entries in round parentheses ( ), whereas bmatrix uses square brackets [ ].
Try your own paper in Texeno.
Start free, upload a project as a .zip and press Recompile. Upgrade when you need longer compiles.
Start writing