How to Create Matrices in LaTeX

Matrices are a very useful way to display rectangular data in rows and columns for technical, mathematical, and scientific documents. This beginner‘s guide will teach you how to create all kinds of matrices in LaTeX using the versatile amsmath package.

Overview of Matrices in LaTeX

Matrices are rectangular arrays of elements arranged in rows and columns. They are enclosed by braces, brackets, parentheses or other delimiters. Matrices are extremely common in math and engineering contexts for representing systems of equations, data transforms, combinatorics problems, graphs, and more.

LaTeX makes handling matrices easy for the user, with a suite of matrix environments that can alter the delimiters and alignment. The amsmath package provides these handy matrix environments which we‘ll cover in this guide.

To use matrices in your LaTeX document, you first need to import the amsmath package in your preamble:

\usepackage{amsmath}

This will give you access to the following matrix environments:

  • matrix – Bare matrices with no delimiters
  • pmatrix – Matrices enclosed in parentheses
  • bmatrix – Matrices enclosed in square brackets
  • Bmatrix – Matrices enclosed in curly braces
  • vmatrix – Matrices with single vertical lines as delimiters
  • Vmatrix – Matrices with double vertical lines as delimiters

Let‘s look at how to create matrices using each of these environments.

Creating Bare Matrices

The matrix environment without any arguments creates a matrix with no delimiters around it. This is useful when the matrix is part of a bigger equation.

\[
\begin{matrix}
   a & b & c \\
   d & e & f \\
   g & h & i
\end{matrix} 
\]

Which renders as:

Bare matrix

Note the use of the \[ \] braces to display the matrix centrally on its own line.

Creating Matrices with Parentheses

To envelop a matrix in parentheses, use the pmatrix environment:

\begin{pmatrix}
  0 & 1 & 2 \\
  3 & 4 & 5 \\
  6 & 7 & 8
\end{pmatrix}

This produces a matrix enclosed in parentheses like so:

Matrix with parentheses

The pmatrix environment adjusts the sizes of the parentheses to tightly wrap the matrix.

Creating Matrices with Brackets

For a matrix surrounded by square brackets, employ the bmatrix environment:

\begin{bmatrix}
   1 & 0 & 0 \\
  -1 & 0 & 3 \\
   a & b & c
\end{bmatrix}

Which generates the following bracketed matrix:

Matrix with brackets

Like pmatrix, bmatrix resizes the brackets based on the matrix dimensions.

Creating Matrices with Braces

To envelop a matrix in curly braces, you can use the Bmatrix environment:

\begin{Bmatrix}
  x & y \\
  z & v
\end{Bmatrix}

This produces a handsome brace-bound matrix:

Matrix with braces

The braces adapt to the width and height of the matrix.

Creating Matrices with Single Pipes

For delimiters made of single vertical bars, employ the vmatrix environment like so:

\begin{vmatrix}
  a & b & c \\
  d & e & f \\
  g & h & i
\end{vmatrix}

Which generates a matrix enclosed in single pipes:

Matrix with single pipes

This gives matrices a nice finished look.

Creating Matrices with Double Pipes

To double up the vertical bar delimiters, use the Vmatrix environment:

\begin{Vmatrix}
  1 & 2 & 3\\
  4 & 5 & 6\\ 
  7 & 8 & 9
\end{Vmatrix}  

This produces a matrix delimited by double pipes:

Matrix with double pipes

The double pipes create a bolder, more visible boundary compared to single pipes.

Creating Matrices with Custom Delimiters

You aren‘t limited to the standard delimiters. You can use any LaTeX math symbols as opening and closing delimiters with the \left and \right commands:

\left\langle
  \begin{matrix}
    1 & 0 & 0\\
    0 & 1 & 0\\
    0 & 0 & 1 
  \end{matrix}
\right\rangle

This generates a matrix enclosed between angle brackets:

Matrix with angle bracket delimiters

You can use any sized opening and closing math delimiters like parentheses, brackets, braces, bars, arrows and more.

Inline and Small Matrices

By default, matrices render centered in display mode. To use a matrix inline with other text, employ the smallmatrix environment:

Math is great with small matrices $\begin{smallmatrix} a & b \\ c & d \end{smallmatrix}$ inline.

This produces an inline matrix:

Small inline matrix

smallmatrix sizes the matrix appropriately to fit inside text.

Assigning Matrices to Symbols

You can assign a matrix to a math symbol like a variable using the equation environment:

\begin{equation*}
   M = \begin{bmatrix}
        1 & 0 & 0\\
        0 & 1 & 0\\
        0 & 0 & 1  
   \end{bmatrix}
\end{equation*}

This neatly assigns our identity matrix to the variable M:

Assigning a matrix

The equation environment numbers equations if used without the * argument.

Common Matrix Modifications

There are a few handy ways to modify matrices by adding rows, columns, changing sizes, colors, and alignments:

  • Add subscripts or superscripts to matrix elements using _ and ^
  • Adjust row spacing with [1ex] between elements
  • Nested matrices by putting a matrix inside another matrix
  • Color rows, columns or elements with \textcolor{red}{...}
  • Transpose a matrix with \matrix{...}^T
  • Display the inverse matrix with \matrix{...}^{-1}
  • Align matrices using the align environment
  • Resize matrices using \smallmatrix, \medmathrix, \bigmatrix

Troubleshooting Matrices

Some common issues when getting started with matrices:

  • Mismatched delimiters from using the wrong environment
  • Column misalignment from inconsistent spacing
  • Overly large gaps between rows from blank lines or unmatched braces
  • Centering issues if not using \[ \] or equation enviroment
  • Inline matrices rendering vertically – use smallmatrix instead

Adjust the column alignments, avoid blank lines inside matrices, and use the appropriate environments to avoid problems.

Why Use Matrices in LaTeX?

Compared to word processors, matrices in LaTeX:

  • Are easier to write with a clean syntax
  • Automatically align and size delimiters
  • Support fine-tuned spacing and alignments
  • Integrate seamlessly with other math expressions
  • Format consistently across devices and outputs
  • Produce professional mathematical typesetting

For any technical document involving matrices like engineering papers, mathematical theorems, data transformations, physics formulas, or statistics, LaTeX can typeset it beautifully.

Final Thoughts

This covers the basics of working with matrices in LaTeX documents. The amsmath package provides an elegant and flexible system for displaying professional matrices with fine-tuned control over delimiters, alignment, and formatting.

Matrices allow LaTeX authors to cleanly present tabular data, sets of equations, statistical results, and multidimensional math concepts. By mastering matrices, you can produce sophisticated mathematical and scientific papers.

Scroll to Top