FormaTeX

\begin{matrix}

LaTeX Matrices

The complete guide to LaTeX matrix syntax — all six matrix environments (pmatrix, bmatrix, vmatrix and more), augmented matrices with the array environment, and multi-column layouts.

\section{Environments}

Matrix environments

amsmath provides six matrix environments, each producing a different bracket style. All use the same row/column syntax — only the surrounding delimiters change.

matrixnone

Bare matrix with no surrounding brackets. Wrap manually in \left( ... \right) if needed.

pmatrix( )

Matrix enclosed in parentheses. The most common form for linear algebra.

bmatrix[ ]

Matrix enclosed in square brackets. Common in engineering and control theory.

Bmatrix{ }

Matrix enclosed in curly braces. Occasionally used for set-builder notation.

vmatrix| |

Matrix enclosed in single vertical bars. Standard notation for determinants.

Vmatrix‖ ‖

Matrix enclosed in double vertical bars. Used for matrix norms.

\begin{pmatrix}

Syntax walkthrough

The matrix syntax mirrors the tabular environment: columns are separated by & and rows end with \\. Unlike tables, you do not specify column alignment — matrix columns are always centered.

\documentclass{article}
\usepackage{amsmath}

\begin{document}

% No delimiters
\[
  \begin{matrix}
    1 & 0 \\ 0 & 1
  \end{matrix}
\]

% Parentheses — pmatrix
\[
  A = \begin{pmatrix}
    a_{11} & a_{12} & a_{13} \\
    a_{21} & a_{22} & a_{23} \\
    a_{31} & a_{32} & a_{33}
  \end{pmatrix}
\]

% Square brackets — bmatrix
\[
  B = \begin{bmatrix} 2 & -1 \\ 3 & 4 \end{bmatrix}
\]

% Vertical bars (determinant) — vmatrix
\[
  \det(A) = \begin{vmatrix} a & b \\ c & d \end{vmatrix} = ad - bc
\]

\end{document}

&

Column separator

Separates entries within a row, just like in tabular.

\\

Row separator

Ends the current row and starts a new one.

a_{ij}

Subscript notation

Standard index notation for the (i, j) entry.

\begin{array}

Augmented matrices with array

amsmath matrix environments do not support a vertical dividing line. For augmented matrices (e.g., for row-reduction), use the built-in array environment inside manual \left[...\right] delimiters. Add a | in the column spec to draw the vertical separator.

\documentclass{article}
\usepackage{amsmath}

\begin{document}

% Augmented matrix — use array with a vertical rule
\[
  \left[\begin{array}{ccc|c}
    1 & 2 & 3 & 4 \\
    0 & 1 & 2 & 3 \\
    0 & 0 & 1 & 2
  \end{array}\right]
\]

% 3x3 identity matrix
\[
  I_3 = \begin{pmatrix}
    1 & 0 & 0 \\
    0 & 1 & 0 \\
    0 & 0 & 1
  \end{pmatrix}
\]

\end{document}

\section{Try it live}

3 × 3 matrix example

Open this complete 3×3 matrix example — including a pmatrix and a vmatrix determinant — directly in the FormaTeX playground and compile it with one click.

\section{Common mistakes}

Avoid these pitfalls

Using matrix environments outside math mode

All amsmath matrix environments must be inside \[...\] or another math environment. Placing \begin{pmatrix} directly in the document body will cause a compilation error.

Inconsistent column counts

Every row must have the same number of & separators. A 3-column matrix needs exactly two & per row. Inconsistent counts produce misaligned output or errors.

Trying to add a vertical line inside pmatrix

pmatrix and its siblings do not accept a column spec, so you cannot insert a | divider. Use the array environment inside \left[...\right] for augmented matrices instead.

\section{FAQ}

Frequently asked questions

What package do I need for LaTeX matrix environments?

All matrix environments (matrix, pmatrix, bmatrix, vmatrix, etc.) are provided by the amsmath package. Add \usepackage{amsmath} to your preamble. The array environment for augmented matrices is built into LaTeX and does not need any extra package.

How do I write a determinant in LaTeX?

Use the vmatrix environment from amsmath: \begin{vmatrix} a & b \\ c & d \end{vmatrix}. This places the matrix between single vertical bars. For a 2×2 determinant the result is |A| = ad - bc.

How do I create an augmented matrix in LaTeX?

Use the array environment with a column spec that includes a vertical bar. For example: \left[\begin{array}{cc|c} a & b & e \\ c & d & f \end{array}\right]. The | in the column spec {cc|c} draws the vertical line separating the coefficient and constant columns.

How many columns can a LaTeX matrix have?

There is no hard limit on matrix columns in standard LaTeX. However, very wide matrices may overflow the text area. For matrices wider than the page, consider using \resizebox from the graphicx package, or splitting the matrix across multiple equations.

How do I add dots (ellipsis) inside a matrix?

Use \cdots for horizontal dots, \vdots for vertical dots, and \ddots for diagonal dots. For example: \begin{pmatrix} 1 & \cdots & n \\ \vdots & \ddots & \vdots \\ n & \cdots & n^2 \end{pmatrix}

FormaTeX Playground

Try these matrix examples live

Compile LaTeX in the browser — pdfLaTeX, XeLaTeX, LuaLaTeX. Free tier, no credit card.

One quick thing

We track anonymous usage — page views, feature usage, compilation events — to understand what works and what doesn't. No ads, no personal data, no third-party sharing.

Cookie policy