About
Shop
LaTeX
Free Software
Books
News
Contact
Blog
News (2018-01-05): glossaries-extra v1.26 released.


9.4.10 Arrays

Mathematical structures such as matrices and vectors require elements to be arranged in rows and columns. Just as we can align material in rows and columns in text mode using the tabular environment (§4.6. Aligning Material in Rows and Columns), we can do the same in maths mode using the array environment. The array environment has the same format as the tabular environment, however it must be in maths mode. The column half-gaps are given by the length register \arraycolsep (analogous to \tabcolsep).

Example:

\[
\begin{array}{rrr}
0 & 1 & 19\\
-6 & 10 & 200
\end{array}
\]

Image shows 3 columns and 2 rows.

Example (Adding Delimiters):

\[
\left(
 \begin{array}{rrr}
   0 & 1 & 19\\
  -6 & 10 & 200
 \end{array}
\right)
\]

Image: as before but has large round brackets on either
side.

Adding a Vertical Rule:

A vertical rule can be added using | in the column specifier. For example:

\[
\left(
 \begin{array}{rr|r}
   0 & 1 & 19\\
  -6 & 10 & 200
 \end{array}
\right)
\]

Image: 3 columns and 2 rows with a vertical line
between the second and third column.

Example (Cases):

This example uses an invisible delimiter:

\[
f(x) =
 \left\{
  \begin{array}{rl}
   -1 & x < 0\\
   0  & x = 0\\
   +1 & x > 0
  \end{array}
 \right.
\]

Image: array has large open brace on the left and
nothing on the right of it.

This can be rewritten more compactly using the amsmath cases environment:

\[
f(x) =
 \begin{cases}
  -1 & x < 0\\
  0 & x = 0\\
  +1 & x > 0
 \end{cases}
\]

Image: as previous example but first column is left
aligned.

The amsmath package provides some convenient environments to typeset matrices: pmatrix, bmatrix, Bmatrix, vmatrix and Vmatrix. These are similar to the array environment except there is no argument, and they add (respectively) $ \bigl( \bigr)$ , $ \bigl[ \bigr]$ , $ \bigl\{ \bigr\}$ , $ \bigl\lvert \bigr\rvert$ and $ \bigl\lVert \bigr\rVert$ delimiters. There is also the matrix environment that doesn't have any delimiters.

Example:

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

Image: 2 by 2 matrix with round delimiters and an
equation number.

The amsmath package also provides the environment smallmatrix designed for in-line use. You need to add any delimiters explicitly.

Example:

Here is a small matrix
\begin{math}
 \left(
  \begin{smallmatrix}
  a & b\\
  c & d
  \end{smallmatrix}
 \right)
\end{math}
in a line of text.

Image: matrix is small enough to fit into the line
of text.


This book is also available as A4 PDF or 12.8cm x 9.6cm PDF or paperback (ISBN 978-1-909440-00-5).

Last modified: 2017-02-06.

The free resources on this site are funded by book sales, not by adverts. If you would like to help keep this site free of annoying third-party ads, please consider buying a book.

© 2012 Dickimaw Books. "Dickimaw", "Dickimaw Books" and the Dickimaw parrot logo are trademarks. The Dickimaw parrot was painted by Magdalene Pritchett.

Terms of Use Privacy Policy Site Map FAQs