Learning how to create a matrix in LaTeX is essential for mathematical typesetting in research papers, textbooks, and technical documentation. The amsmath package provides six standard LaTeX matrix environments (pmatrix, bmatrix, vmatrix, and more) that handle all delimiter styles automatically. Whether you need a simple 2×2 matrix with parentheses, a determinant with vertical bars, or complex augmented matrices with custom spacing, this comprehensive guide covers everything from basic syntax to advanced formatting techniques.
Package required : Most LaTeX matrix environments need \usepackage{amsmath}. Some advanced features require additional packages like array or mathtools.Related topics : Mathematical equations | Subscripts & superscripts | LaTeX symbols Last updated : January 2026 | Reading time : 15 min | Difficulty : Beginner to Intermediate
What You’ll Learn
✅ All LaTeX matrix environments (pmatrix, bmatrix, vmatrix, Bmatrix, Vmatrix)
✅ Creating arrays with custom delimiters and column alignment
✅ Block matrices and augmented matrix notation
✅ Matrix operations, determinants, and transpose notation
✅ Small inline matrices with smallmatrix environment
✅ Advanced matrix formatting, spacing, and decorations
✅ Troubleshooting common LaTeX matrix issues
Frequently Asked Questions
What is the difference between pmatrix and bmatrix in LaTeX?
The main difference between pmatrix and bmatrix is the type of delimiters (brackets) they use:
pmatrix uses parentheses ( ) - most common for general matrices in mathematics
bmatrix uses square brackets [ ] - preferred for numerical data and engineering
Both require the amsmath package and work identically in terms of syntax: % Using pmatrix (parentheses)
$ A = \begin { pmatrix } 1 & 2 \\ 3 & 4 \end { pmatrix } $
% Using bmatrix (square brackets)
$ B = \begin { bmatrix } 1 & 2 \\ 3 & 4 \end { bmatrix } $
When to use each:
Use pmatrix for: linear transformations, general matrices, mathematical proofs
Use bmatrix for: numerical data, matrices in data science, engineering applications
Use vmatrix for: determinants (single vertical bars)
How do I create a matrix with vertical lines between columns (augmented matrix)?
To create an augmented matrix with vertical lines separating columns, use the array environment with the pipe symbol | in the column specification: \[
\left[ \begin { array }{cc|c}
1 & 2 & 5 \\
3 & 4 & 11
\end { array }\right]
\]
How it works:
{cc|c} means: column-center, column-center, vertical line , column-center
Use c for centered, l for left-aligned, r for right-aligned
The pipe | symbol creates the vertical separator line
Use \left[ and \right] to automatically scale brackets
What is the amsmath package and why do I need it for LaTeX matrices?
The amsmath package (American Mathematical Society) provides essential matrix environments that aren’t available in plain LaTeX:
pmatrix (parentheses)
bmatrix (square brackets)
vmatrix (determinant notation)
Vmatrix (norm notation)
Bmatrix (curly braces)
smallmatrix (inline matrices)
How to load it: \documentclass { article }
\usepackage { amsmath }
Without amsmath, you’d be limited to the basic array environment with manual delimiter management.
How do I fix alignment issues with numbers in LaTeX matrices?
Number alignment problems occur when columns contain different-width numbers. Use these solutions:Solution 1: Right-aligned array \left [ \begin { array } {rr}
1.2 & 345.6 \\
12.34 & 5.6
\end { array } \right ]
Solution 2: Use siunitx for decimal alignment \usepackage { siunitx }
\begin { array } {SS}
1.2 & 345.6 \\
12.34 & 5.6
\end { array }
Solution 3: Use phantom spacing \phantom {0}1.2 % Adds invisible space
How do I create a small inline matrix in LaTeX?
For matrices within text paragraphs , use the smallmatrix environment: The rotation matrix $ \left( \begin { smallmatrix }
\cos \theta & -\sin \theta \\
\sin \theta & \cos \theta
\end { smallmatrix }\right) $ transforms points in 2D space.
Regular pmatrix environments are too large for inline use and disrupt line spacing. The smallmatrix environment uses smaller fonts and tighter spacing.
What does the array column specifier mean in LaTeX matrices?
Column specifiers define how each column is formatted:Specifier Alignment Example lLeft {lll}cCenter {ccc}rRight {rrr}|Vertical line {c|c}@{text}Custom separator @{,}
Example with vertical line: \begin { array } {cc|c}
1 & 2 & 5 \\
3 & 4 & 11
\end { array }
How do I calculate and display a determinant in LaTeX?
Use the vmatrix environment for determinant notation with vertical bar delimiters: \det (A) = \begin { vmatrix }
a & b \\
c & d
\end { vmatrix } = ad - bc
For 3×3 matrices: \begin { vmatrix }
a_{ 11 } & a_{ 12 } & a_{ 13 } \\
a_{ 21 } & a_{ 22 } & a_{ 23 } \\
a_{ 31 } & a_{ 32 } & a_{ 33 }
\end { vmatrix }
How do I increase spacing between elements in a LaTeX matrix?
Use \renewcommand{\arraystretch}{factor} to control matrix element spacing : % 50% more space between rows
{ \renewcommand { \arraystretch }{1.5}
$ \begin { pmatrix }
a & b \\
c & d
\end { pmatrix } $ }
Recommended values:
1.0 - Default compact spacing
1.2 - Standard matrices
1.5 - Matrices with fractions or subscripts
2.0 - Matrices with tall expressions
Use curly braces to limit the effect to just one matrix.
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 pmatrix: ( a b c d ) \begin{pmatrix} a & b \\ c & d \end{pmatrix} ( a c b d ) bmatrix: [ 1 2 3 4 5 6 7 8 9 ] \begin{bmatrix} 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 9 \end{bmatrix} 1 4 7 2 5 8 3 6 9 Bmatrix: { x 1 x 2 x 3 } \begin{Bmatrix} x_1 \\ x_2 \\ x_3 \end{Bmatrix} ⎩ ⎨ ⎧ x 1 x 2 x 3 ⎭ ⎬ ⎫ vmatrix (determinant): ∣ a b c d ∣ = a d − b c \begin{vmatrix} a & b \\ c & d \end{vmatrix} = ad - bc a c b d = a d − b c Vmatrix (norm): ∥ 1 2 3 4 ∥ \begin{Vmatrix} 1 & 2 \\ 3 & 4 \end{Vmatrix} 1 3 2 4 matrix (no delimiters): a b c d \begin{matrix} a & b \\ c & d \end{matrix} a c b d
Matrix Environment Summary Table
Environment Delimiters Common Use Example matrixNone Building block for custom delimiters Basic array pmatrix( ) General matrices, transformations Linear algebra bmatrix[ ] General matrices, data tables Numerical data BmatrixSet notation, systems Set theory vmatrix| | Determinants det(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 = ( 1 2 3 4 ) A = \begin{pmatrix} 1 & 2 \\ 3 & 4 \end{pmatrix} A = ( 1 3 2 4 ) is invertible. The general form is ( a b c d ) \begin{pmatrix} a & b \\ c & d \end{pmatrix} ( a c b d ) where a d − b c ≠ 0 ad - bc \neq 0 a d − b c = 0 . Matrix equation:
( 2 1 1 3 ) ( x y ) = ( 5 7 ) \begin{pmatrix} 2 & 1 \\ 1 & 3 \end{pmatrix} \begin{pmatrix} x \\ y \end{pmatrix} = \begin{pmatrix} 5 \\ 7 \end{pmatrix} ( 2 1 1 3 ) ( x y ) = ( 5 7 )
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_{ 1 n} \\
a_{ 21 } & a_{ 22 } & \cdots & a_{ 2 n} \\
\vdots & \vdots & \ddots & \vdots \\
a_{m 1 } & a_{m 2 } & \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:
A = ( a 11 a 12 ⋯ a 1 n a 21 a 22 ⋯ a 2 n ⋮ ⋮ ⋱ ⋮ a m 1 a m 2 ⋯ a m n ) 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} A = a 11 a 21 ⋮ a m 1 a 12 a 22 ⋮ a m 2 ⋯ ⋯ ⋱ ⋯ a 1 n a 2 n ⋮ a mn Column vector: x = ( x 1 x 2 x 3 ⋮ x n ) \mathbf{x} = \begin{pmatrix} x_1 \\ x_2 \\ x_3 \\ \vdots \\ x_n \end{pmatrix} x = x 1 x 2 x 3 ⋮ x n Row vector: y T = ( y 1 y 2 y 3 ⋯ y n ) \mathbf{y}^T = \begin{pmatrix} y_1 & y_2 & y_3 & \cdots & y_n \end{pmatrix} y T = ( y 1 y 2 y 3 ⋯ y n )
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_{ 1 n} \\
a_{ 21 } & a_{ 22 } & \cdots & a_{ 2 n} \\
\vdots & \vdots & \ddots & \vdots \\
a_{m 1 } & a_{m 2 } & \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_{ 1 n} \\
A_{ 21 } & A_{ 22 } & \cdots & A_{ 2 n} \\
\vdots & \vdots & \ddots & \vdots \\
A_{m 1 } & A_{m 2 } & \cdots & A_{mn}
\end { pmatrix } $
\end { document }
Rendered Output General matrix with dots:
[ a 11 a 12 ⋯ a 1 n a 21 a 22 ⋯ a 2 n ⋮ ⋮ ⋱ ⋮ a m 1 a m 2 ⋯ a m n ] \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} a 11 a 21 ⋮ a m 1 a 12 a 22 ⋮ a m 2 ⋯ ⋯ ⋱ ⋯ a 1 n a 2 n ⋮ a mn Diagonal matrix:
D = [ d 1 0 ⋯ 0 0 d 2 ⋱ ⋮ ⋮ ⋱ ⋱ 0 0 ⋯ 0 d n ] D = \begin{bmatrix} d_1 & 0 & \cdots & 0 \\ 0 & d_2 & \ddots & \vdots \\ \vdots & \ddots & \ddots & 0 \\ 0 & \cdots & 0 & d_n \end{bmatrix} D = d 1 0 ⋮ 0 0 d 2 ⋱ ⋯ ⋯ ⋱ ⋱ 0 0 ⋮ 0 d n
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 3 = ( 1 0 0 0 1 0 0 0 1 ) I_3 = \begin{pmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \end{pmatrix} I 3 = 1 0 0 0 1 0 0 0 1 Zero matrix: 0 3 × 3 = ( 0 0 0 0 0 0 0 0 0 ) \mathbf{0}_{3 \times 3} = \begin{pmatrix} 0 & 0 & 0 \\ 0 & 0 & 0 \\ 0 & 0 & 0 \end{pmatrix} 0 3 × 3 = 0 0 0 0 0 0 0 0 0 Ones matrix: 1 2 × 3 = ( 1 1 1 1 1 1 ) \mathbf{1}_{2 \times 3} = \begin{pmatrix} 1 & 1 & 1 \\ 1 & 1 & 1 \end{pmatrix} 1 2 × 3 = ( 1 1 1 1 1 1 )
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 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 ) 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} U = u 11 0 0 0 u 12 u 22 0 0 u 13 u 23 u 33 0 u 14 u 24 u 34 u 44 Lower triangular:
L = ( 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 ) 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} L = l 11 l 21 l 31 l 41 0 l 22 l 32 l 42 0 0 l 33 l 43 0 0 0 l 44 Tridiagonal:
T = ( 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 ) 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} T = a 1 c 1 0 0 b 1 a 2 c 2 0 0 b 2 a 3 c 3 0 0 b 3 a 4
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 & = & 2 y + 3 z \\
2 x - y & = & 7 \\
x + 3 y & = & 4 z - 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 column alignments (center, right, left):
center right left a + b 12.34 x y z c 5.6 p q r s \begin{array}{crl} \text{center} & \text{right} & \text{left} \\ a + b & 12.34 & xyz \\ c & 5.6 & pqrs \end{array} center a + b c right 12.34 5.6 left x yz pq rs Array with vertical lines and horizontal rule:
[ 1 2 3 4 5 6 7 8 ] \left[\begin{array}{c|cc|c} 1 & 2 & 3 & 4 \\ \hline 5 & 6 & 7 & 8 \end{array}\right] [ 1 5 2 6 3 7 4 8 ] System of equations with custom spacing:
\begin{array}{r@{\,}c@{\,}l} x &=& 2y + 3z \\ 2x - y &=& 7 \\ x + 3y &=& 4z - 1 \end{array}
Array Column Specifiers
Specifier Alignment Description lLeft Left-aligned column cCenter Centered column rRight Right-aligned column p{width}Paragraph Fixed 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 } \\ [ 1 em]
\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.5 em]
\begin { matrix } g & h \end { matrix } & i
\end { pmatrix } $
\end { document }
Rendered Output Simple 2x2 block matrix: M = ( A B C D ) M = \begin{pmatrix} A & B \\ C & D \end{pmatrix} M = ( A C B D ) Block matrix with dividing lines:
[ A B C D ] \left[\begin{array}{c|c} A & B \\ \hline C & D \end{array}\right] [ A C B D ] Mixed size blocks (2x2 matrix with vector and scalar):
( a b c d e f g h i ) \begin{pmatrix} \begin{matrix} a & b \\ c & d \end{matrix} & \begin{matrix} e \\ f \end{matrix} \\ \begin{matrix} g & h \end{matrix} & i \end{pmatrix} a c b d g h e f i
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 - 2 R_ 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:
[ 1 2 3 6 4 5 6 15 7 8 9 24 ] \left[\begin{array}{ccc|c} 1 & 2 & 3 & 6 \\ 4 & 5 & 6 & 15 \\ 7 & 8 & 9 & 24 \end{array}\right] 1 4 7 2 5 8 3 6 9 6 15 24 Row reduction example:
[ 1 2 − 1 3 2 − 1 3 7 − 1 3 2 0 ] → R 2 − 2 R 1 [ 1 2 − 1 3 0 − 5 5 1 − 1 3 2 0 ] \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] 1 2 − 1 2 − 1 3 − 1 3 2 3 7 0 R 2 − 2 R 1 1 0 − 1 2 − 5 3 − 1 5 2 3 1 0 Extended augmentation:
[ a b e 1 0 c d f 0 1 ] \left[\begin{array}{cc|c|cc} a & b & e & 1 & 0 \\ c & d & f & 0 & 1 \end{array}\right] [ a c b d e f 1 0 0 1 ]
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:
A B = ( a b c d ) ( e f g h ) = ( a e + b g a f + b h c e + d g c f + d h ) 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} A B = ( a c b d ) ( e g f h ) = ( a e + b g ce + d g a f + bh c f + d h ) Matrix transpose:
A T = ( 1 2 3 4 5 6 ) T = ( 1 4 2 5 3 6 ) A^T = \begin{pmatrix} 1 & 2 & 3 \\ 4 & 5 & 6 \end{pmatrix}^T = \begin{pmatrix} 1 & 4 \\ 2 & 5 \\ 3 & 6 \end{pmatrix} A T = ( 1 4 2 5 3 6 ) T = 1 2 3 4 5 6 2x2 matrix inverse formula:
A − 1 = ( a b c d ) − 1 = 1 a d − b c ( d − b − c a ) A^{-1} = \begin{pmatrix} a & b \\ c & d \end{pmatrix}^{-1} = \frac{1}{ad-bc} \begin{pmatrix} d & -b \\ -c & a \end{pmatrix} A − 1 = ( a c b d ) − 1 = a d − b c 1 ( d − c − b a )
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 2x2 determinant calculation:
det ( A ) = ∣ a b c d ∣ = a d − b c \det(A) = \begin{vmatrix} a & b \\ c & d \end{vmatrix} = ad - bc det ( A ) = a c b d = a d − b c 3x3 determinant:
∣ a 11 a 12 a 13 a 21 a 22 a 23 a 31 a 32 a 33 ∣ \begin{vmatrix} a_{11} & a_{12} & a_{13} \\ a_{21} & a_{22} & a_{23} \\ a_{31} & a_{32} & a_{33} \end{vmatrix} a 11 a 21 a 31 a 12 a 22 a 32 a 13 a 23 a 33 Trace example: tr ( 5 2 1 3 7 4 6 8 9 ) = 5 + 7 + 9 = 21 \text{tr}\begin{pmatrix} 5 & 2 & 1 \\ 3 & 7 & 4 \\ 6 & 8 & 9 \end{pmatrix} = 5 + 7 + 9 = 21 tr 5 3 6 2 7 8 1 4 9 = 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 θ ) \left(\begin{smallmatrix} \cos\theta & -\sin\theta \\ \sin\theta & \cos\theta \end{smallmatrix}\right) ( c o s θ s i n θ − s i n θ c o s θ ) rotates vectors by angle θ \theta θ . The Pauli matrices are σ x = ( 0 1 1 0 ) \sigma_x = \left(\begin{smallmatrix} 0 & 1 \\ 1 & 0 \end{smallmatrix}\right) σ x = ( 0 1 1 0 ) , σ y = ( 0 − i i 0 ) \sigma_y = \left(\begin{smallmatrix} 0 & -i \\ i & 0 \end{smallmatrix}\right) σ y = ( 0 i − i 0 ) , and σ z = ( 1 0 0 − 1 ) \sigma_z = \left(\begin{smallmatrix} 1 & 0 \\ 0 & -1 \end{smallmatrix}\right) σ z = ( 1 0 0 − 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 1 Col 2 Col 3 Row 1 a 11 a 12 a 13 Row 2 a 21 a 22 a 23 Row 3 a 31 a 32 a 33 \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} Row 1 Row 2 Row 3 Col 1 a 11 a 21 a 31 Col 2 a 12 a 22 a 32 Col 3 a 13 a 23 a 33 Correlation matrix example:
R = X Y Z X 1.00 0.85 0.42 Y 0.85 1.00 0.67 Z 0.42 0.67 1.00 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} R = X Y Z X 1.00 0.85 0.42 Y 0.85 1.00 0.67 Z 0.42 0.67 1.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 (colored):
( 1 0 0 0 2 0 0 0 3 ) \begin{pmatrix} \color{red}1 & 0 & 0 \\ 0 & \color{red}2 & 0 \\ 0 & 0 & \color{red}3 \end{pmatrix} 1 0 0 0 2 0 0 0 3 Boxed identity matrix elements:
( 1 0 0 0 1 0 0 0 1 ) \begin{pmatrix} \boxed{1} & 0 & 0 \\ 0 & \boxed{1} & 0 \\ 0 & 0 & \boxed{1} \end{pmatrix} 1 0 0 0 1 0 0 0 1 Matrix equation with labels:
( 2 1 1 3 ) ⏟ A ( x y ) ⏟ x = ( 5 7 ) ⏟ b \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}} A ( 2 1 1 3 ) x ( x y ) = b ( 5 7 ) Annotated matrix:
( a 11 a 12 a 13 a 21 a 22 a 23 a 31 a 32 a 33 ) ← row 1 ← row 2 ← row 3 \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} a 11 a 21 a 31 a 12 a 22 a 32 a 13 a 23 a 33 ← row 1 ← row 2 ← row 3
Common Pitfalls and Solutions
My matrix delimiters are too small
Problem : Parentheses/brackets don’t scale with matrix size.Solution : Use \left and \right with array:$ \left( \begin { array }{cc}
a & b \\
c & d
\end { array }\right) $
Or use the pre-defined environments like pmatrix which handle this automatically.
Alignment issues in matrices
Problem : Numbers don’t align properly in columns.Solution :
Use array with explicit alignment: {rrr} for right-aligned
For decimals, use the siunitx package with S columns
Add spacing with \phantom{} for consistent widths
Problem : Large matrices extend beyond margins.Solutions :
Use \small or \footnotesize before the matrix
Use bmatrix*}[r] from mathtools for right-aligned entries
Split into block matrices
Consider using array environment with custom column spacing
Spacing between matrix elements
Problem : Elements too cramped or too spread out.Solution : Adjust array stretch:\renewcommand { \arraystretch }{1.5} % 1.5x normal spacing
\begin { pmatrix }
a & b \\
c & d
\end { pmatrix }
Best Practices
Matrix typesetting guidelines:
Choose appropriate delimiters : Use vmatrix for determinants, pmatrix for general matrices
Consistency : Use the same notation style throughout your document
Size considerations : Use smallmatrix for inline matrices
Alignment : Right-align numbers in numeric matrices
Spacing : Add \, or \: for better readability when needed
Block structure : Use block matrices to show structure
Labels : Add row/column labels when they aid understanding
Package Recommendations
Essential Packages
Package Purpose Key Features amsmathBasic matrix environments All standard matrix types mathtoolsExtended matrix features Starred versions, more options arrayCustom column types Full control over layout siunitxNumeric alignment Decimal alignment in matrices blkarrayBlock arrays Labels and blocks nicematrixEnhanced matrices Many 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_{ 1 n} \\
\vdots & \ddots & \vdots \\
a_{m 1 } & \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 }
Further Reading & References
For authoritative documentation on LaTeX matrix environments and mathematical typesetting:
amsmath Package Documentation - The standard package providing all matrix environments (pmatrix, bmatrix, vmatrix)
mathtools Package - Extended features for matrices including starred versions and additional options
The LaTeX Companion (3rd Edition) - Comprehensive reference for mathematical typesetting best practices
Linear Algebra Done Right by Sheldon Axler - Standard textbook demonstrating matrix notation conventions
LaTeX Cloud Studio tip: Use our real-time preview feature to instantly see how your matrices render. No compilation wait time needed!