Math-Linux.com

Knowledge base dedicated to Linux and applied mathematics.

Home > Latex > FAQ > Latex - FAQ > How to write matrices in Latex ? matrix, pmatrix, bmatrix, vmatrix, (...)

How to write matrices in Latex ? matrix, pmatrix, bmatrix, vmatrix, Vmatrix

Here are few examples to write quickly matrices.


First of all, modify your preamble adding

\usepackage{amsfonts}

LateX pmatrix, bmatrix, vmatrix, Vmatrix

pmatrix, bmatrix, vmatrix, Vmatrix are Latex environments:

  • p for parens
  • b for brackets
  • v for verts
  • B for braces
  • V for double verts.

How to write an m x n matrix in LaTeX

\begin{equation*}
A_{m,n} =
\begin{pmatrix}
a_{1,1} & a_{1,2} & \cdots & a_{1,n} \\
a_{2,1} & a_{2,2} & \cdots & a_{2,n} \\
\vdots  & \vdots  & \ddots & \vdots  \\
a_{m,1} & a_{m,2} & \cdots & a_{m,n}
\end{pmatrix}
\end{equation*}

$$ \begin{equation*} A_{m,n} = \begin{pmatrix} a_{1,1} & a_{1,2} & \cdots & a_{1,n} \\ a_{2,1} & a_{2,2} & \cdots & a_{2,n} \\ \vdots & \vdots & \ddots & \vdots \\ a_{m,1} & a_{m,2} & \cdots & a_{m,n} \end{pmatrix} \end{equation*} $$

Examples matrix 3 x 3 in LaTeX

\begin{equation*}
A =
\begin{pmatrix}
1 & 2 & 3 \\
4 & 5 & 6 \\
7 & 8 & 9
\end{pmatrix}
\end{equation*}

$$ \begin{equation*} A = \begin{pmatrix} 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 9 \end{pmatrix} \end{equation*} $$

\begin{equation*}
B =
\begin{bmatrix}
a & b & c \\
d & e & f \\
g & h & i
\end{bmatrix}
\end{equation*}

$$ \begin{equation*} B = \begin{bmatrix} a & b & c \\ d & e & f \\ g & h & i \end{bmatrix} \end{equation*} $$

LateX matrix with no bracket

\begin{equation}
  \begin{matrix}
  a_{11} & a_{12} & a_{13}  \\
  a_{21} & a_{22} & a_{23}  \\
  a_{31} & a_{32} & a_{33}  \\
  \end{matrix}
\end{equation}

$$ \begin{equation} \begin{matrix} a_{11} & a_{12} & a_{13} \\ a_{21} & a_{22} & a_{23} \\ a_{31} & a_{32} & a_{33} \\ \end{matrix} \end{equation} $$

LateX matrix determinant / vertical bar bracket

\begin{equation}
  \begin{vmatrix}
  a_{11} & a_{12} & a_{13}  \\
  a_{21} & a_{22} & a_{23}  \\
  a_{31} & a_{32} & a_{33}  \\
  \end{vmatrix}
\end{equation}

$$ \begin{equation} \begin{vmatrix} a_{11} & a_{12} & a_{13} \\ a_{21} & a_{22} & a_{23} \\ a_{31} & a_{32} & a_{33} \\ \end{vmatrix} \end{equation} $$

Latex matrix with curly brackets

\begin{equation}
  \begin{Bmatrix}
  a_{11} & a_{12} & a_{13}  \\
  a_{21} & a_{22} & a_{23}  \\
  a_{31} & a_{32} & a_{33}  \\
  \end{Bmatrix}
\end{equation}

$$ \begin{equation} \begin{Bmatrix} a_{11} & a_{12} & a_{13} \\ a_{21} & a_{22} & a_{23} \\ a_{31} & a_{32} & a_{33} \\ \end{Bmatrix} \end{equation} $$

Latex matrix with double vertical bar brackets

\begin{equation}
  \begin{Vmatrix}
  a_{11} & a_{12} & a_{13}  \\
  a_{21} & a_{22} & a_{23}  \\
  a_{31} & a_{32} & a_{33}  \\
  \end{Vmatrix}
\end{equation}

$$ \begin{equation} \begin{Vmatrix} a_{11} & a_{12} & a_{13} \\ a_{21} & a_{22} & a_{23} \\ a_{31} & a_{32} & a_{33} \\ \end{Vmatrix} \end{equation} $$

Latex small inline matrix

Use smallmatrix environment

I love small matrice such $\big(\begin{smallmatrix} a & b\\ c & d \end{smallmatrix}\big)$

I love small matrice such $\big(\begin{smallmatrix} a & b\\ c & d \end{smallmatrix}\big)$

Examples matrix 2 x 2 in LaTeX

Here are examples with matrix 2x2 with pmatrix, bmatrix, vmatrix, Vmatrix environments:

\begin{matrix} 
a & b \\
c & d
\end{matrix}
\quad
\begin{pmatrix}
a & b \\
c & d
\end{pmatrix}
\quad
\begin{bmatrix}
a & b \\
c & d
\end{bmatrix}
\quad
\begin{vmatrix}
a & b \\
c & d
\end{vmatrix}
\quad
\begin{Vmatrix}
a & b \\
c & d
\end{Vmatrix}

$$ \begin{matrix} a & b \\ c & d \end{matrix} \quad \begin{pmatrix} a & b \\ c & d \end{pmatrix} \quad \begin{bmatrix} a & b \\ c & d \end{bmatrix} \quad \begin{vmatrix} a & b \\ c & d \end{vmatrix} \quad \begin{Vmatrix} a & b \\ c & d \end{Vmatrix} $$