# Matrices in LaTeX

## Array Environment

For more control over your matrices, one useful tool provided by LaTeX is the array environment. It only needs the number of columns and their alignment as a parameter. Since we are creating a matrix, we probably need all elements centered. In that case, we can use the letter c as many as the number of columns to declare the centering alignment option. Then, we can type the elements of the matrix by separating each column inside a row with &, and separating rows with \\. This environment only creates a grid for the contents of our matrix, so if we need brackets, we need to declare them separately. In the following example, we created a matrix with two rows and two columns inside brackets:

$A_{2\times2} = \left[ {\begin{array}{cc} a_{11} & a_{12} \\ a_{21} & a_{22} \\ \end{array} } \right]$

Below, there are two more examples, in which we explored the array environment with different sizes and contents.

$A_{3\times5} = \left[ {\begin{array}{ccccc} a_{11} & a_{12} & a_{13} & a_{14} & a_{15}\\ a_{21} & a_{22} & a_{23} & a_{24} & a_{25}\\ a_{31} & a_{32} & a_{33} & a_{34} & a_{35}\\ \end{array} } \right]$
$A_{m\times n} = \left[ {\begin{array}{cccc} 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{array} } \right]$

## Amsmath Package

The amsmath package provides commands to typeset matrices with different delimiters. Once you have loaded \usepackage{amsmath} in your document, you can use the following set of commands in your math environments:

Let’s go over these commands. In the following examples, we demonstrated different kinds of delimiter options that comes with the amsmath package.

$A_{2\times 3} = \begin{matrix} a_{11} & a_{12} & a_{13}\\ a_{21} & a_{22} & a_{23} \end{matrix}$
$A_{3\times 2} = \begin{pmatrix} a_{11} & a_{12}\\ a_{21} & a_{22}\\ a_{31} & a_{32} \end{pmatrix}$
$A_{4\times 3} = \begin{bmatrix} a_{11} & a_{12} & a_{13}\\ a_{21} & a_{22} & a_{23}\\ a_{31} & a_{32} & a_{33}\\ a_{41} & a_{42} & a_{43} \end{bmatrix}$
$A_{3\times 4} = \begin{Bmatrix} a_{11} & a_{12} & a_{13} & a_{14}\\ a_{21} & a_{22} & a_{23} & a_{24}\\ a_{31} & a_{32} & a_{33} & a_{34} \end{Bmatrix}$
$A_{3\times 3} = \begin{vmatrix} a_{11} & a_{12} & a_{13}\\ a_{21} & a_{22} & a_{23}\\ a_{31} & a_{32} & a_{33} \end{vmatrix}$
$A_{3\times 3} = \begin{Vmatrix} a_{11} & a_{12} & a_{13}\\ a_{21} & a_{22} & a_{23}\\ a_{31} & a_{32} & a_{33} \end{Vmatrix}$

If we need another type of delimiter, we add them just like we did in the array environment, only this time we will use the plain matrix command. The following example shows two different matrices with different sets of brackets.

$A_{2\times 2} = \left\lceil \begin{matrix} a_{11} & a_{12}\\ a_{21} & a_{22} \end{matrix} \right\rceil$

$A_{3\times 3} = \left\langle \begin{matrix} a_{11} & a_{12} & a_{13}\\ a_{21} & a_{22} & a_{23}\\ a_{31} & a_{32} & a_{33} \end{matrix} \right\rangle$

The amsmath package additionally provides a smaller size option, which is especially useful when typing a matrix within a paragraph. In the next example, we created a small matrix below a regular matrix.

$A_{3\times 3} = \begin{pmatrix} a_{11} & a_{12} & a_{13}\\ a_{21} & a_{22} & a_{23}\\ a_{31} & a_{32} & a_{33} \end{pmatrix}$

$A_{3\times 3} = \left(\begin{smallmatrix} a_{11} & a_{12} & a_{13}\\ a_{21} & a_{22} & a_{23}\\ a_{31} & a_{32} & a_{33} \end{smallmatrix}\right)$

## FAQ

Question 1: How to write m × n matrix in LaTeX using array?
A number of examples regarding matrices with different dimensions are mentioned in the Array Environment section. The array environment requires the user to specify the number of columns in its command: \begin{array}{}. The second brace defines the number of columns in the matrix.

Question 2: What is the easiest way to type matrices in LaTeX?
The easiest way to type matrices is to use the amsmath package. This package allows writing matrices with different commands, illustrated in detail in the Amsmath Package section.

Question 3: When typing a matrix in LaTeX, which method provides better spacing?
The illustrations provided in sections Array Environment and Amsmath Package concludes that the matrices created using the amsmath package have better spacing than the matrices created by using the array environment.