Skip to content
site-logo
  • Home
  • JavaScript
  • Machine Learning
  • C++Expand
    • C++ Programing
    • Numerical Techniques C++
    • Data Structures C++
    • C++ Programs
  • Typing Guide
  • Blogs
site-logo
Home / Tech Updates / How to Write Matrix in LaTeX?

How to Write Matrix in LaTeX?

ByLonz Updated onJuly 7, 2023
Tech Updates
latex code for matrix
Ad
Table of contents
  1. Write Matrices in Latex
    1. Latex Code For Matrix
    2. Brackets in Latex
      1. Latex pmatrix, bmatrix, vmatrix, Vmatrix
  2. How to write an m * n matrix in LaTeX
  3. How to Write 3 x 3 Matrix in LaTeX
    1. 3 x 3 Matrix with parentheses:
    2. 3 x 3 Matrix with brackets:
    3. 3 x 3 Matrix with no bracket
    4. 3 x 3 Matrix with Vertical Bar | Determinant
    5. 3 x 3 Latex matrix with curly brackets
    6. Latex matrix with double vertical bar brackets
  4. How to Write 2 x 2 Matrix in LaTeX
    1. pmatrix
    2. bmatrix
    3. vmatrix
    4. Vmatrix

The important feature of latex is to display mathematical and scientific formulas and equations in their original style and to make math equations look beautiful on our web or other important documents.

Write Matrices in Latex

There are a few ways to enter math mode, however, the most common is

Ad
    $..inline math..$
or
    $$ ..math in new line.. $$

where the text within the dollar signs is in the math mode environment.

And the other method is by using the command,

\begin{equation} and \end{equation}

There are equivalent ways of entering math mode for each of these methods as in the below example, however, the latter is now strongly preferred.

$$....$$ is equivalent to \[ ....\]

Latex Code For Matrix

A matrix can be described as a rectangular array of numbers, symbols, or expressions that are arranged in rows and columns. A matrix in LaTeX can be generated with the help of a math environment for typesetting matrices.

For generating matrix in LaTeX we have to use the package amsmath by giving the command:

\usepackage{amsmath}

	\documentclass{article}
	\usepackage{amsmath}
	\begin{document}
	$$
	\begin{bmatrix} 
	a & b & c \\
	c & d & d\\
	e & f & g \\
	\end{bmatrix}
	\quad
	$$
	\end{document}
Code language: JavaScript (javascript)

Note: If you are using online Latex code editor then copy only the equation part.

Output of the above code

Brackets in Latex

Latex pmatrix, bmatrix, vmatrix, Vmatrix

There can be various types of brackets to use in a matrix. Some of them are discussed below:

Ad
  • p for parentheses
  • b for square brackets
  • v for verts
  • B for curly braces
  • V for double vertical bars.

Code Explanation:

  • \begin{matrix} This command creates a matrix without brackets.
  • \begin{pmatrix} This command creates a matrix with parenthesis.
  • \begin{bmatrix} This command creates a matrix with square brackets.
  • \begin{Bmatrix} This command creates a matrix with curly brackets.
  • \begin{vmatrix} This command creates a matrix with a rectangular line boundary.
  • \begin{Vmatrix} This command creates a matrix with double vertical bar brackets.


How to write an m * n matrix in LaTeX

Latex Code for m * n Matrix

$$\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 & \vdots & \vdots\\ 
a_{m,1} & a_{m,2} & \cdots & a_{m,n} 
\end{pmatrix} 
\end{equation}
$$

Output of m * n matrix:

m*n matrix

How to Write 3 x 3 Matrix in LaTeX

3 x 3 Matrix with parentheses:

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

3 x 3 Matrix with brackets:

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

Output:

3*3 bmatrix

3 x 3 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}

Output:

3*3 no bracket matrix

3 x 3 Matrix with Vertical Bar | Determinant

\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}

Output:

3*3 vmatrix

3 x 3 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}

Output:

3*3 bmatrix curly

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}

Output:

How to Write 2 x 2 Matrix in LaTeX


Here are some examples of 2 x 2 matrix with pmatrix, bmatrix, vmatrix, Vmatrix.

\begin{matrix}
a & b\\
c & d
\end{matrix}

Output:

pmatrix

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

Output:

bmatrix

\begin{bmatrix}
a & b\\
c & d
\end{bmatrix}

Output:

vmatrix

\begin{vmatrix}
a & b\\
c & d
\end{vmatrix}

Vmatrix

\begin{Vmatrix}
a & b\\
c & d
\end{Vmatrix}

End Thanks!

Post navigation

Previous Previous
Typing Test Paragraph
NextContinue
Tree Data Structure | Tree Terminologies | Tree Traversal
Search

  • Home
  • Privacy Policy
  • Disclaimer
  • Sitemap
  • Write for us
  • Contact Us

Copyright © 2025 TechInDetail

Scroll to top
  • Home
  • JavaScript
  • Machine Learning
  • C++
    • C++ Programing
    • Numerical Techniques C++
    • Data Structures C++
    • C++ Programs
  • Typing Guide
  • Blogs
Search