In mathematics, a matrix is a rectangular arrangement of elements. These elements can be used for mathematical operations and are a key concept in linear algebra. LaTeX is a popular programming language, especially in the field of mathematics, for representing complex formulas and calculations. In this tip and tricks article, we will show you how to successfully create matrices in LaTeX using arrays and the amsmath package.

## Creating a Matrix Using the Array Environment

Within the LaTeX standard, a matrix can be inserted into your document using the array environment. However, you need to define the required columns and their alignment beforehand. Additionally, the matrix’s bracketing needs to be defined; otherwise, the number array would be displayed without brackets, thus not representing a matrix. Nevertheless, with a few commands, this can be done quickly. In our example, we will use the identity matrix since it is generally familiar. To create a regular number array, you can use the following code:

“`

$\begin{array}{rrr}

1 & 0 & 0 \\

0 & 1 & 0 \\

0 & 0 & 1 \\

\end{array}$

“`

Here’s what the individual commands mean:

Starting from this example, you can define a matrix with the corresponding brackets. To do this, you need to enter the brackets using the commands `\left` and `\right` before opening and after closing the math environment in the LaTeX code.

* Round brackets:

“`

$\left( \begin{array}{rrr}

1 & 0 & 0 \\

0 & 1 & 0 \\

0 & 0 & 1 \\

\end{array}\right)$

“`

* Square brackets:

“`

$\left[ \begin{array}{rrr}

1 & 0 & 0 \\

0 & 1 & 0 \\

0 & 0 & 1 \\

\end{array}\right]$

“`

## Creating a Matrix Using the amsmath Package

By importing the `amsmath` package at the beginning of your document, you have access to six different matrix environments. To do this, you need to include `\usepackage{amsmath}` in the preamble. The number of columns is recognized automatically, which is a significant advantage over the number array. Here’s the minimal example for a matrix without brackets and then all the options:

* Without brackets:

“`

$\begin{matrix}

1 & 0 & 0 \\

0 & 1 & 0 \\

0 & 0 & 1 \\

\end{matrix}$

“`

Replace the above `matrix` command with the following options for the desired output:

×