Skip to content
All LaTeX symbols

Matrices in LaTeX (pmatrix, bmatrix)

Delimiters

[ ]

LaTeX command

\begin{pmatrix} a & b \\ c & d \end{pmatrix}

round brackets ( )

Write the environment in math mode, usually display math. Use & between entries and \\ between rows.

A matrix is a grid of entries: & moves to the next column and \\ starts a new row. The environment name sets the brackets, so pmatrix gives round ones and bmatrix square ones, and you never size the brackets by hand.

All ways to write it

  • \begin{pmatrix} a & b \\ c & d \end{pmatrix}round brackets ( )Package: amsmath
  • \begin{bmatrix} a & b \\ c & d \end{bmatrix}square brackets [ ]Package: amsmath
  • \begin{vmatrix} a & b \\ c & d \end{vmatrix}vertical bars, for a determinantPackage: amsmath
  • \begin{Bmatrix} ... \end{Bmatrix}curly braces { }Package: amsmath
  • \begin{Vmatrix} ... \end{Vmatrix}double bars, for a normPackage: amsmath
  • \begin{matrix} ... \end{matrix}no bracketsPackage: amsmath
  • \begin{smallmatrix} ... \end{smallmatrix}a small matrix for inline math; add the brackets yourselfPackage: amsmath
  • \begin{array}{cc|c} ... \end{array}augmented matrix: | in the column spec draws the line; wrap it in \left[ \right]No package needed
  • \cdots \vdots \ddotshorizontal, vertical and diagonal dots for an n × n matrixNo package needed

Commands marked with a package need that \usepackage line in a LaTeX document.

Example

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}

A general m × n matrix in square brackets, with dots standing in for the rows and columns in between.

Questions

How do I write a matrix in LaTeX?

Load amsmath and use \begin{bmatrix} ... \end{bmatrix} for square brackets or pmatrix for round ones. Separate the entries in a row with & and end each row with \\.

What is the difference between pmatrix, bmatrix and vmatrix?

Only the brackets: pmatrix ( ), bmatrix [ ], Bmatrix { }, vmatrix | | for a determinant, Vmatrix || || for a norm, and matrix with none. The entries are written the same way in all of them.

How do I write a determinant?

Use vmatrix, for example \det(A) = \begin{vmatrix} a & b \\ c & d \end{vmatrix} = ad - bc.

How do I draw a line in an augmented matrix?

Use array inside brackets and put | in the column spec where the line goes: \left[ \begin{array}{cc|c} ... \end{array} \right]. Plain array needs no package and works in KaTeX.

How do I write the identity matrix?

Either spell it out, \begin{pmatrix} 1 & 0 \\ 0 & 1 \end{pmatrix}, or write I_n for the n × n identity, which is the usual notation in running text.

Do matrices work in KaTeX and Confluence?

Yes. KaTeX renders matrix, pmatrix, bmatrix, Bmatrix, vmatrix, Vmatrix, smallmatrix and array. In Confluence put larger matrices in a block math macro, where they get their own line at full size.

Using matrix in Confluence

Confluence Cloud has no built-in LaTeX. With LaTeX Math for Confluence you add a math macro to any page, type \begin{pmatrix} a & b \\ c & d \end{pmatrix} and it renders inline or as a block, with a live preview while you edit. Every command on this page renders there without extra packages.

Related symbols

Also in Delimiters

See all LaTeX symbols