Lesson 1 of 3

Matrices and Arrays

Learn how to typeset beautiful matrices with different bracket styles.

Writing a matrix in LaTeX requires the amsmath package, which is the gold standard for math typesetting. (Don't worry, in LetX and most modern templates, this package is already included).

The Matrix Environments

LaTeX provides several matrix environments. The only difference between them is the type of bracket (or lack thereof) surrounding the matrix.

  • matrix: No brackets
  • pmatrix: Parentheses ()
  • bmatrix: Square brackets []
  • Bmatrix: Curly braces {}
  • vmatrix: Vertical lines || (useful for determinants)
  • Vmatrix: Double vertical lines || ||

Building a Matrix

Inside a matrix environment, you build the grid row by row.

  • Use an ampersand & to separate columns.
  • Use a double backslash \\ to end a row and start a new one.
\[
M = \begin{bmatrix}
    1 & 2 & 3 \\
    4 & 5 & 6 \\
    7 & 8 & 9
\end{bmatrix}
\]

You can make them as large as you want, and the brackets will automatically scale to fit the contents perfectly!

Vectors

A vector is just a matrix with a single column.

\[
\vec{v} = \begin{pmatrix}
    x_1 \\
    y_1 \\
    z_1
\end{pmatrix}
\]
Ellipses in Matrices

When writing theoretical, n-dimensional matrices, you often need dots.

  • \dots gives horizontal dots
  • \vdots gives vertical dots
  • \ddots gives diagonal dots

Example of a theoretical matrix:

\[
A = \begin{bmatrix}
    a_{11} & a_{12} & \dots  & a_{1n} \\
    a_{21} & a_{22} & \dots  & a_{2n} \\
    \vdots & \vdots & \ddots & \vdots \\
    a_{m1} & a_{m2} & \dots  & a_{mn}
\end{bmatrix}
\]

Knowledge Check

Knowledge Check

If you want to typeset the determinant of a matrix, which environment automatically wraps the grid in single vertical lines |...|?