Skip to main content
v2026.11,858 entries · CC-BY 4.0

Matrix in LaTeX: pmatrix, bmatrix and More

How to typeset a matrix in LaTeX with amsmath: pmatrix, bmatrix and the other environments, the 10-column limit, inline matrices and alignment.

Written and maintained by CASRAI Editorial Board

Last updated

A matrix in LaTeX is typeset with one of the matrix environments from the amsmath package: pmatrix for parentheses, bmatrix for square brackets, Bmatrix for curly braces, vmatrix for single bars, Vmatrix for double bars, and plain matrix for no delimiters. This guide covers the syntax, the choice between these environments and array, and the limits that most short tutorials leave out, such as the default ten-column cap. It is about LaTeX typesetting only.

What it is used for in research

Matrices appear in research writing wherever an array of quantities has to sit inside an equation: coefficient arrays, transformation arrays, covariance arrays and similar objects. In LaTeX the matrix environments exist so the delimiters, spacing and alignment of those arrays are produced by the document rather than drawn by hand. The environments belong to amsmath, the package documented in the amsmath User’s Guide on CTAN. The same source describes the matrix environments as using more economical horizontal spacing than the general-purpose array environment, which is why they are the usual choice for matrices in equations.

Install or access (official source only)

The amsmath User’s Guide states that amsmath is normally provided along with an up-to-date LaTeX installation, so there is usually nothing to download. Load it in the preamble:

\usepackage{amsmath}

Overleaf’s Learn page on matrices gives the same requirement: the matrix environments need \usepackage{amsmath}. The package documentation itself is hosted on CTAN (see Sources). If your project is on Overleaf, the guide to collaborative writing in LaTeX and Overleaf covers the workflow around the editor.

Step-by-step: typeset a matrix

  1. Add \usepackage{amsmath} to the preamble, before \begin{document}.
  2. Choose the environment that has the delimiters you want (see the table in the next section). Delimiters are built in for pmatrix, bmatrix, Bmatrix, vmatrix and Vmatrix; matrix has none.
  3. Write the entries row by row. Separate columns with & and end each row with \\. You do not give a column specification, unlike array.
  4. Place the environment in math mode and compile.

The example below is the form shown on Overleaf’s Learn page:

\begin{pmatrix}
1 & 2 & 3 \\
a & b & c
\end{pmatrix}

To use delimiters that the built-in environments do not offer, Overleaf shows wrapping a plain matrix in \left and \right, for example with \langle and \rangle.

Rows of dots with hdotsfor

Inside a matrix, \hdotsfor{number} produces a row of dots spanning that many columns. The amsmath User’s Guide example is:

\begin{matrix}
a & b & c & d \\
e & \hdotsfor{3}
\end{matrix}

An optional argument scales the dot spacing, as in \hdotsfor[1.5]{3}; the default multiplier is 1.0.

A matrix inside a line of text

For a small matrix in running text, use smallmatrix. According to the amsmath User’s Guide, it is suitable for use in text, and its delimiters must be provided by you. The guide’s example uses \bigl( and \bigr):

\bigl( \begin{smallmatrix} a & b \\ c & d \end{smallmatrix} \bigr)

Overleaf’s page shows the same idea as $\big(\begin{smallmatrix} a & b \\ c & d \end{smallmatrix}\big)$. Both sources note that the mathtools package provides ready-made delimited versions, such as psmallmatrix and bsmallmatrix, so you do not have to add the delimiters by hand.

Output and how to read it

Each environment differs only in the delimiters drawn around the entries. The delimiters come from the amsmath User’s Guide, section on matrices.

Environment Delimiters
matrix None
pmatrix Parentheses ( )
bmatrix Square brackets [ ]
Bmatrix Curly braces { }
vmatrix Single vertical bars | |
Vmatrix Double vertical bars
smallmatrix None built in; add them yourself or use the mathtools small variants

Entries in these environments are centered in their columns by default.

Troubleshooting

The matrix stops at ten columns

The matrix environments allow up to 10 centered columns by default. The limit is stored in the counter MaxMatrixCols, whose normal value is 10. Raise it with \setcounter or \addtocounter, for example \setcounter{MaxMatrixCols}{20}.

Entries need left or right alignment

The matrix environments center their columns. The amsmath User’s Guide gives two routes to other alignment: use the array environment, or load mathtools, which provides starred (*) variants of these environments that take an optional argument for left or right alignment. The exact argument syntax is in the mathtools documentation on CTAN, linked in the Sources section.

A small inline matrix has no brackets

That is expected: smallmatrix has no built-in delimiters. Add them with \bigl and \bigr, or use the mathtools variants.

Undefined environment error

If the compiler reports an undefined environment such as pmatrix, check that \usepackage{amsmath} is in the preamble, since the delimited environments are defined there.

Free alternatives (table)

These are the free ways to build the same kind of array.

Option Notes
array environment Requires a column specification; uses wider horizontal spacing than the matrix environments; gives control over left and right alignment (amsmath User’s Guide).
mathtools package Starred variants of the matrix environments with an optional alignment argument; delimited smallmatrix variants (amsmath User’s Guide, Overleaf Learn).
\left and \right around plain matrix Lets you choose delimiters the built-in environments do not offer (Overleaf Learn).

For other LaTeX tasks in the same document, see the guides on figures in LaTeX, citations and bibliographies in Overleaf and LaTeX bibliography styles.

FAQ

How do I put parentheses or brackets around a LaTeX matrix?

Use pmatrix for parentheses or bmatrix for square brackets. Both have their delimiters built in once amsmath is loaded.

How many columns can a LaTeX matrix have?

Up to 10 by default. The limit is the MaxMatrixCols counter, which you can change with \setcounter{MaxMatrixCols}{N}.

How do I write a matrix inside a sentence?

Use smallmatrix and supply the delimiters yourself, or use the mathtools variants psmallmatrix and bsmallmatrix.

What is the difference between matrix and array?

The matrix environments need no column specification and use more economical spacing; array needs a column specification and is the route to left or right alignment.

Sources (official docs)

Checked 2026-10-29.

Follow CASRAI

Research-administration guidance, standards updates and independent tool reviews.

Ask CASRAI · free to try

Ask about Matrix in LaTeX: pmatrix, bmatrix and More

Ask your first 2 questions free below. Subscribers get 150 a day for $29 a month.

An AI assistant specialized in research administration. It cites the sources behind every answer, labels web answers and says when it can't answer.

Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.

Works on this site and inside Claude, Cursor and the AI tools you already use.

Everything CASRAI publishes — this page, the dictionary, the guides and the news — stays free to read, with no account and no card.

Referenced across the research world

University of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logoUniversity of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logo
  • University of Cambridge logo
  • Columbia University logo
  • Crossref logo
  • University of Edinburgh logo
  • Harvard University logo
  • University of Oxford logo
  • Princeton University logo
  • Stanford School of Medicine logo
  • University College London logo
  • ORCID logo

View CASRAI adoption →

Ask CASRAI · Regulatory Radar

Research-admin question? Get an answer that links its sources.

An AI assistant specialized in research administration. Every answer links its sources to check before you act. 2 questions free, no account. $29/month after.

  • Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.
  • Every answer numbers its sources and links each one, so you can check the source yourself.