Matrices in LaTeX

The article discusses different methods to create matrices in LaTeX by using both array and amsmath package. A number of methods involving various types of matrices are represented with the help of illustrations.

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_ = \left[  a_ & a_ \\ a_ & a_ \\ \end > \right] \]

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

\[ A_ = \left[  a_ & a_ & a_ & a_ & a_\\ a_ & a_ & a_ & a_ & a_\\ a_ & a_ & a_ & a_ & a_\\ \end > \right] \]

\[ A_ = \left[  a_ & a_ & \cdots & a_\\ a_ & a_ & \cdots & a_\\ \vdots & \vdots & \ddots & \vdots\\ a_ & a_ & \cdots & a_\\ \end > \right] \]

Amsmath Package

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

\[ A_ = \begin a_ & a_\\ a_ & a_\\ a_ & a_ \end \]

\[ A_ = \begin a_ & a_ & a_\\ a_ & a_ & a_\\ a_ & a_ & a_\\ a_ & a_ & a_ \end \]

\[ A_ = \begin a_ & a_ & a_ & a_\\ a_ & a_ & a_ & a_\\ a_ & a_ & a_ & a_ \end \]

\[ A_ = \begin a_ & a_ & a_\\ a_ & a_ & a_\\ a_ & a_ & a_ \end \]

\[ A_ = \begin a_ & a_ & a_\\ a_ & a_ & a_\\ a_ & a_ & a_ \end \]

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_ = \left\lceil \begin a_ & a_\\ a_ & a_ \end \right\rceil \] \[ A_ = \left\langle \begin a_ & a_ & a_\\ a_ & a_ & a_\\ a_ & a_ & a_ \end \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_ = \begin a_ & a_ & a_\\ a_ & a_ & a_\\ a_ & a_ & a_ \end \] \[ A_ = \left(\begin a_ & a_ & a_\\ a_ & a_ & a_\\ a_ & a_ & a_ \end\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<> . 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.