Learn how to create professional matrices in LaTeX with this comprehensive guide. From basic 2×2 matrices to complex block structures, master all matrix environments and techniques for mathematical typesetting.

Package required: Most matrix environments need \usepackage{amsmath}. Some advanced features require additional packages like array or mathtools.

Related topics: Mathematical equations | Table creation | Mathematical symbols

What You’ll Learn

  • ✅ All matrix environments (pmatrix, bmatrix, vmatrix, etc.)
  • ✅ Creating arrays with custom delimiters
  • ✅ Block matrices and augmented matrices
  • ✅ Matrix operations and notation
  • ✅ Small inline matrices
  • ✅ Advanced formatting and decorations
  • ✅ Troubleshooting common issues

Basic Matrix Environments

LaTeX provides six standard matrix environments through the amsmath package, each with different delimiters:

Matrix Environment Overview

\documentclass{article}
\usepackage{amsmath}
\begin{document}

% Parentheses matrix (most common)
$\begin{pmatrix}
a & b \\
c & d
\end{pmatrix}$

% Square bracket matrix
$\begin{bmatrix}
1 & 2 & 3 \\
4 & 5 & 6 \\
7 & 8 & 9
\end{bmatrix}$

% Curly brace matrix
$\begin{Bmatrix}
x_1 \\
x_2 \\
x_3
\end{Bmatrix}$

% Determinant (vertical bars)
$\begin{vmatrix}
a & b \\
c & d
\end{vmatrix} = ad - bc$

% Norm (double vertical bars)
$\begin{Vmatrix}
\mathbf{v}
\end{Vmatrix} = \begin{Vmatrix}
1 & 2 \\
3 & 4
\end{Vmatrix}$

% No delimiters
$\begin{matrix}
a & b \\
c & d
\end{matrix}$

\end{document}

Rendered output:

All matrix environments with different delimiters:
pmatrix

(

a  bc  d

)

bmatrix

[

1  2  34  5  67  8  9

]

Bmatrix
vmatrix

|

a  bc  d

| = ad - bc

Vmatrix

1  23  4

matrix
a  bc  d

Matrix Environment Summary Table

EnvironmentDelimitersCommon UseExample
matrixNoneBuilding block for custom delimitersBasic array
pmatrix( )General matrices, transformationsLinear algebra
bmatrix[ ]General matrices, data tablesNumerical data
BmatrixSet notation, systemsSet theory
vmatrix| |Determinantsdet(A)
Vmatrix|| ||Norms, magnitudes||v||

Creating Your First Matrix

Simple 2×2 Matrix

\documentclass{article}
\usepackage{amsmath}
\begin{document}

% Basic 2x2 matrix
The matrix $A = \begin{pmatrix}
1 & 2 \\
3 & 4
\end{pmatrix}$ is invertible.

% With variables
The general form is $\begin{pmatrix}
a & b \\
c & d
\end{pmatrix}$ where $ad - bc \neq 0$.

% Matrix equation
$\begin{pmatrix}
2 & 1 \\
1 & 3
\end{pmatrix}
\begin{pmatrix}
x \\
y
\end{pmatrix}
=
\begin{pmatrix}
5 \\
7
\end{pmatrix}$

\end{document}

Rendered output:

The matrix A = (

1234) is invertible.

The general form is (

abcd

) where ad - bc ≠ 0.

(2113)(xy)=(57)

Key points for matrix creation:

  • Use & to separate columns
  • Use \\ to end rows
  • Don’t add \\ after the last row
  • Matrices must be in math mode ($...$ or \[...\])

Matrix Elements and Structure

Matrix with Subscripts

\documentclass{article}
\usepackage{amsmath}
\begin{document}

% General m×n matrix
$A = \begin{pmatrix}
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{pmatrix}$

% 3×3 example
$B = \begin{bmatrix}
b_{11} & b_{12} & b_{13} \\
b_{21} & b_{22} & b_{23} \\
b_{31} & b_{32} & b_{33}
\end{bmatrix}$

% Column vector
$\mathbf{x} = \begin{pmatrix}
x_1 \\
x_2 \\
x_3 \\
\vdots \\
x_n
\end{pmatrix}$

% Row vector
$\mathbf{y}^T = \begin{pmatrix}
y_1 & y_2 & y_3 & \cdots & y_n
\end{pmatrix}$

\end{document}

Rendered output:

General m×n matrix with subscript notation:
A = (a₁₁a₁₂a₁ₙa₂₁a₂₂a₂ₙaₘ₁aₘ₂aₘₙ)
Column and row vectors:
Column vector
x = (x₁x₂x₃xₙ)
Row vector
yT = (y₁  y₂  y₃  ⋯  yₙ)

Using Dots in Matrices

LaTeX provides three types of dots for indicating patterns in matrices:

\documentclass{article}
\usepackage{amsmath}
\begin{document}

% Horizontal dots: \cdots
% Vertical dots: \vdots  
% Diagonal dots: \ddots

% General matrix pattern
$\begin{bmatrix}
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{bmatrix}$

% Diagonal matrix
$D = \begin{bmatrix}
d_1 & 0 & \cdots & 0 \\
0 & d_2 & \ddots & \vdots \\
\vdots & \ddots & \ddots & 0 \\
0 & \cdots & 0 & d_n
\end{bmatrix}$

% Block pattern
$\begin{pmatrix}
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{pmatrix}$

\end{document}

Rendered output:

Different types of dots in matrices:
General matrix with all dot types
[a₁₁a₁₂a₁ₙa₂₁a₂₂a₂ₙaₘ₁aₘ₂aₘₙ]
Diagonal matrix pattern
D = [d₁000d₂000dₙ]

Special Matrix Types

Identity and Zero Matrices

\documentclass{article}
\usepackage{amsmath}
\begin{document}

% Identity matrix
$I_3 = \begin{pmatrix}
1 & 0 & 0 \\
0 & 1 & 0 \\
0 & 0 & 1
\end{pmatrix}$

% General identity
$I_n = \begin{pmatrix}
1 & 0 & \cdots & 0 \\
0 & 1 & \cdots & 0 \\
\vdots & \vdots & \ddots & \vdots \\
0 & 0 & \cdots & 1
\end{pmatrix}$

% Zero matrix
$\mathbf{0}_{3 \times 3} = \begin{pmatrix}
0 & 0 & 0 \\
0 & 0 & 0 \\
0 & 0 & 0
\end{pmatrix}$

% Ones matrix
$\mathbf{1}_{2 \times 3} = \begin{pmatrix}
1 & 1 & 1 \\
1 & 1 & 1
\end{pmatrix}$

\end{document}

Rendered output:

3×3 Identity matrix
I = (100010001)
3×3 Zero matrix
0₃ₓ₃ = (000000000)
2×3 Ones matrix
1₂ₓ₃ = (111111)

Triangular Matrices

\documentclass{article}
\usepackage{amsmath}
\begin{document}

% Upper triangular
$U = \begin{pmatrix}
u_{11} & u_{12} & u_{13} & u_{14} \\
0 & u_{22} & u_{23} & u_{24} \\
0 & 0 & u_{33} & u_{34} \\
0 & 0 & 0 & u_{44}
\end{pmatrix}$

% Lower triangular
$L = \begin{pmatrix}
l_{11} & 0 & 0 & 0 \\
l_{21} & l_{22} & 0 & 0 \\
l_{31} & l_{32} & l_{33} & 0 \\
l_{41} & l_{42} & l_{43} & l_{44}
\end{pmatrix}$

% Strictly upper triangular
$U_0 = \begin{pmatrix}
0 & u_{12} & u_{13} \\
0 & 0 & u_{23} \\
0 & 0 & 0
\end{pmatrix}$

% Tridiagonal
$T = \begin{pmatrix}
a_1 & b_1 & 0 & 0 \\
c_1 & a_2 & b_2 & 0 \\
0 & c_2 & a_3 & b_3 \\
0 & 0 & c_3 & a_4
\end{pmatrix}$

\end{document}

Rendered output:

Upper triangular
U = (u₁₁u₁₂u₁₃u₁₄0u₂₂u₂₃u₂₄00u₃₃u₃₄000u₄₄)
Lower triangular
L = (l₁₁000l₂₁l₂₂00l₃₁l₃₂l₃₃0l₄₁l₄₂l₄₃l₄₄)
Tridiagonal
T = (a₁b₁00c₁a₂b₂00c₂a₃b₃00c₃a₄)

Arrays - The Foundation of Matrices

The array environment provides the most flexibility for creating custom matrix-like structures:

Basic Array Usage

\documentclass{article}
\usepackage{amsmath}
\begin{document}

% Basic array with alignment
$\begin{array}{crl}
\text{center} & \text{right} & \text{left} \\
a + b & 12.34 & xyz \\
c & 5.6 & pqrs
\end{array}$

% Array with vertical lines
$\left[\begin{array}{c|cc|c}
1 & 2 & 3 & 4 \\
\hline
5 & 6 & 7 & 8
\end{array}\right]$

% Custom spacing
$\begin{array}{r@{\,}c@{\,}l}
x &=& 2y + 3z \\
2x - y &=& 7 \\
x + 3y &=& 4z - 1
\end{array}$

% Mixed content
$\begin{array}{|l|c|}
\hline
\text{Type} & \text{Matrix} \\
\hline
\text{Identity} & \begin{pmatrix} 1 & 0 \\ 0 & 1 \end{pmatrix} \\
\hline
\text{Zero} & \begin{pmatrix} 0 & 0 \\ 0 & 0 \end{pmatrix} \\
\hline
\end{array}$

\end{document}

Rendered output:

Array with different column alignments (center, right, left):
centerrightleft
a + b12.34xyz
c5.6pqrs
Array with vertical lines and horizontal rule:
[
1234
5678
]
System of equations with custom spacing:
x=2y + 3z
2x − y=7
x + 3y=4z − 1

Array Column Specifiers

SpecifierAlignmentDescription
lLeftLeft-aligned column
cCenterCentered column
rRightRight-aligned column
p{width}ParagraphFixed width with text wrapping
``Vertical line between columns
@{text}Custom separator (replaces default spacing)
*{n}{spec}Repeat specifier n times

Block Matrices

Block matrices are used to partition large matrices into smaller submatrices:

Basic Block Matrices

\documentclass{article}
\usepackage{amsmath}
\begin{document}

% Simple 2×2 block matrix
$M = \begin{pmatrix}
A & B \\
C & D
\end{pmatrix}$

% With array for lines
$\left[\begin{array}{c|c}
A & B \\
\hline
C & D
\end{array}\right]$

% Detailed block matrix
$\begin{pmatrix}
\begin{matrix}
a_{11} & a_{12} \\
a_{21} & a_{22}
\end{matrix} & 
\begin{matrix}
b_{11} & b_{12} \\
b_{21} & b_{22}
\end{matrix} \\[1em]
\begin{matrix}
c_{11} & c_{12} \\
c_{21} & c_{22}
\end{matrix} & 
\begin{matrix}
d_{11} & d_{12} \\
d_{21} & d_{22}
\end{matrix}
\end{pmatrix}$

% Mixed size blocks
$\begin{pmatrix}
A_{2 \times 2} & \mathbf{b}_{2 \times 1} \\
\mathbf{c}_{1 \times 2} & d_{1 \times 1}
\end{pmatrix}
= 
\begin{pmatrix}
\begin{matrix}
a & b \\
c & d
\end{matrix} & \begin{matrix} e \\ f \end{matrix} \\[0.5em]
\begin{matrix} g & h \end{matrix} & i
\end{pmatrix}$

\end{document}

Rendered output:

Simple 2×2 block matrix:
M = (ABCD)
Block matrix with dividing lines:
[
AB
CD
]
Mixed size blocks (2×2 matrix with vector and scalar):
(
ab
cd
e
f
g  hi
)

Augmented Matrices

Augmented matrices are commonly used for solving systems of linear equations:

\documentclass{article}
\usepackage{amsmath}
\begin{document}

% Basic augmented matrix
$\left[\begin{array}{ccc|c}
1 & 2 & 3 & 6 \\
4 & 5 & 6 & 15 \\
7 & 8 & 9 & 24
\end{array}\right]$

% Row reduction example
$\left[\begin{array}{rrr|r}
1 & 2 & -1 & 3 \\
2 & -1 & 3 & 7 \\
-1 & 3 & 2 & 0
\end{array}\right]
\xrightarrow{R_2 - 2R_1}
\left[\begin{array}{rrr|r}
1 & 2 & -1 & 3 \\
0 & -5 & 5 & 1 \\
-1 & 3 & 2 & 0
\end{array}\right]$

% Extended augmentation
$\left[\begin{array}{cc|c|cc}
a & b & e & 1 & 0 \\
c & d & f & 0 & 1
\end{array}\right]$

\end{document}

Rendered output:

Augmented matrix for system of equations:
[
1236
45615
78924
]
Row reduction example:
[
12−13
2−137
−1320
]
R₂ − 2R₁
[
12−13
0−551
−1320
]

Matrix Operations

Basic Operations Notation

\documentclass{article}
\usepackage{amsmath}
\begin{document}

% Matrix multiplication
$AB = \begin{pmatrix}
a & b \\
c & d
\end{pmatrix}
\begin{pmatrix}
e & f \\
g & h
\end{pmatrix}
= \begin{pmatrix}
ae + bg & af + bh \\
ce + dg & cf + dh
\end{pmatrix}$

% Transpose
$A^T = \begin{pmatrix}
1 & 2 & 3 \\
4 & 5 & 6
\end{pmatrix}^T
= \begin{pmatrix}
1 & 4 \\
2 & 5 \\
3 & 6
\end{pmatrix}$

% Inverse (2×2 formula)
$A^{-1} = \begin{pmatrix}
a & b \\
c & d
\end{pmatrix}^{-1}
= \frac{1}{ad-bc}
\begin{pmatrix}
d & -b \\
-c & a
\end{pmatrix}$

% Matrix power
$A^2 = AA = \begin{pmatrix}
1 & 2 \\
3 & 4
\end{pmatrix}^2
= \begin{pmatrix}
7 & 10 \\
15 & 22
\end{pmatrix}$

\end{document}

Rendered output:

Matrix multiplication:
AB = (abcd)(efgh) = (ae + bgaf + bhce + dgcf + dh)
Matrix transpose:
AT = (123456)T = (142536)
2×2 matrix inverse formula:
A−1 = (abcd)−1 =
1ad − bc
(d−b−ca)

Determinants and Traces

\documentclass{article}
\usepackage{amsmath}
\begin{document}

% 2×2 determinant
$\det(A) = \begin{vmatrix}
a & b \\
c & d
\end{vmatrix} = ad - bc$

% 3×3 determinant
$\begin{vmatrix}
a_{11} & a_{12} & a_{13} \\
a_{21} & a_{22} & a_{23} \\
a_{31} & a_{32} & a_{33}
\end{vmatrix}$

% Alternative notations
$|A| = \det(A) = \det\begin{pmatrix}
1 & 2 \\
3 & 4
\end{pmatrix} = -2$

% Trace
$\text{tr}(A) = \sum_{i=1}^n a_{ii} = a_{11} + a_{22} + \cdots + a_{nn}$

% Example
$\text{tr}\begin{pmatrix}
5 & 2 & 1 \\
3 & 7 & 4 \\
6 & 8 & 9
\end{pmatrix} = 5 + 7 + 9 = 21$

\end{document}

Rendered output:

2×2 determinant calculation:
det(A) = |abcd| = ad − bc
Trace example:
tr(521374689) = 5 + 7 + 9 = 21

Small Inline Matrices

For matrices within text, use the smallmatrix environment:

\documentclass{article}
\usepackage{amsmath}
\begin{document}

% Inline matrix in text
The rotation matrix $\left(\begin{smallmatrix}
\cos\theta & -\sin\theta \\
\sin\theta & \cos\theta
\end{smallmatrix}\right)$ rotates vectors by angle $\theta$.

% Pauli matrices
The Pauli matrices are 
$\sigma_x = \left(\begin{smallmatrix}
0 & 1 \\
1 & 0
\end{smallmatrix}\right)$,
$\sigma_y = \left(\begin{smallmatrix}
0 & -i \\
i & 0
\end{smallmatrix}\right)$, and
$\sigma_z = \left(\begin{smallmatrix}
1 & 0 \\
0 & -1
\end{smallmatrix}\right)$.

% Custom command for convenience
\newcommand{\mat}[1]{\left(\begin{smallmatrix}#1\end{smallmatrix}\right)}
Then we can write $A = \mat{a & b \\ c & d}$ inline.

\end{document}

Rendered output:

The rotation matrix (cos θ−sin θsin θcos θ) rotates vectors by angle θ.
The Pauli matrices are σₓ = (0110), σᵧ = (0−ii0), and σᴢ = (100−1).

Advanced Techniques

Matrices with Labels

\documentclass{article}
\usepackage{amsmath}
\usepackage{blkarray} % For labeled matrices
\begin{document}

% Using array for labels
$\begin{array}{c|ccc}
& \text{Col 1} & \text{Col 2} & \text{Col 3} \\
\hline
\text{Row 1} & a_{11} & a_{12} & a_{13} \\
\text{Row 2} & a_{21} & a_{22} & a_{23} \\
\text{Row 3} & a_{31} & a_{32} & a_{33}
\end{array}$

% Using blkarray package
$\begin{blockarray}{cccc}
& x_1 & x_2 & x_3 \\
\begin{block}{c(ccc)}
y_1 & 0.8 & 0.1 & 0.1 \\
y_2 & 0.2 & 0.7 & 0.1 \\
y_3 & 0.1 & 0.2 & 0.7 \\
\end{block}
\end{blockarray}$

% Correlation matrix example
$R = \begin{array}{c|ccc}
& X & Y & Z \\
\hline
X & 1.00 & 0.85 & 0.42 \\
Y & 0.85 & 1.00 & 0.67 \\
Z & 0.42 & 0.67 & 1.00
\end{array}$

\end{document}

Rendered output:

Matrix with row and column labels:
Col 1Col 2Col 3
Row 1a₁₁a₁₂a₁₃
Row 2a₂₁a₂₂a₂₃
Row 3a₃₁a₃₂a₃₃
Correlation matrix example:
R =
XYZ
X1.000.850.42
Y0.851.000.67
Z0.420.671.00

Matrix Decorations

\documentclass{article}
\usepackage{amsmath}
\usepackage{color}
\begin{document}

% Highlighting diagonal elements
$\begin{pmatrix}
\color{red}1 & 0 & 0 \\
0 & \color{red}2 & 0 \\
0 & 0 & \color{red}3
\end{pmatrix}$

% Boxed elements
$\begin{pmatrix}
\boxed{1} & 0 & 0 \\
0 & \boxed{1} & 0 \\
0 & 0 & \boxed{1}
\end{pmatrix}$

% Matrix equation with decorations
$\underbrace{\begin{pmatrix}
2 & 1 \\
1 & 3
\end{pmatrix}}_{A}
\underbrace{\begin{pmatrix}
x \\
y
\end{pmatrix}}_{\mathbf{x}}
=
\underbrace{\begin{pmatrix}
5 \\
7
\end{pmatrix}}_{\mathbf{b}}$

% Annotated matrix
$\left(\begin{array}{ccc}
a_{11} & a_{12} & a_{13} \\
a_{21} & a_{22} & a_{23} \\
a_{31} & a_{32} & a_{33}
\end{array}\right)
\begin{array}{l}
\leftarrow \text{row 1} \\
\leftarrow \text{row 2} \\
\leftarrow \text{row 3}
\end{array}$

\end{document}

Rendered output:

Highlighted diagonal elements:
(100020003)
Matrix equation with labels:
(2113)
A
(xy)
x

=

(57)
b

Common Pitfalls and Solutions

Best Practices

Matrix typesetting guidelines:

  1. Choose appropriate delimiters: Use vmatrix for determinants, pmatrix for general matrices
  2. Consistency: Use the same notation style throughout your document
  3. Size considerations: Use smallmatrix for inline matrices
  4. Alignment: Right-align numbers in numeric matrices
  5. Spacing: Add \, or \: for better readability when needed
  6. Block structure: Use block matrices to show structure
  7. Labels: Add row/column labels when they aid understanding

Package Recommendations

Essential Packages

PackagePurposeKey Features
amsmathBasic matrix environmentsAll standard matrix types
mathtoolsExtended matrix featuresStarred versions, more options
arrayCustom column typesFull control over layout
siunitxNumeric alignmentDecimal alignment in matrices
blkarrayBlock arraysLabels and blocks
nicematrixEnhanced matricesMany advanced features

Loading Order

\usepackage{amsmath}     % Load first
\usepackage{mathtools}   % Extends amsmath
\usepackage{array}       % For custom columns
\usepackage{siunitx}     % For numeric columns

Quick Reference Card

Matrix Environments Summary

% Basic environments (requires amsmath)
\begin{matrix}   ... \end{matrix}     % no delimiters
\begin{pmatrix}  ... \end{pmatrix}    % parentheses ( )
\begin{bmatrix}  ... \end{bmatrix}    % brackets [ ]
\begin{Bmatrix}  ... \end{Bmatrix}    % braces { }
\begin{vmatrix}  ... \end{vmatrix}    % single bars | |
\begin{Vmatrix}  ... \end{Vmatrix}    % double bars || ||

% Small matrices (inline)
\begin{smallmatrix} ... \end{smallmatrix}

% Custom delimiters with array
\left[\begin{array}{cc} ... \end{array}\right]

Common Patterns

% Identity matrix
\begin{pmatrix}
1 & 0 & 0 \\
0 & 1 & 0 \\
0 & 0 & 1
\end{pmatrix}

% General element notation
\begin{pmatrix}
a_{11} & \cdots & a_{1n} \\
\vdots & \ddots & \vdots \\
a_{m1} & \cdots & a_{mn}
\end{pmatrix}

% Augmented matrix
\left[\begin{array}{cc|c}
a & b & e \\
c & d & f
\end{array}\right]

% Block matrix
\begin{pmatrix}
A & B \\
C & D
\end{pmatrix}

Next steps: