Skip to main content
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 symbolsLast 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

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)
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
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.
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
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.
Column specifiers define how each column is formatted:
SpecifierAlignmentExample
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}
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}
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: (abcd)\begin{pmatrix} a & b \\ c & d \end{pmatrix}bmatrix: [123456789]\begin{bmatrix} 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 9 \end{bmatrix}Bmatrix: {x1x2x3}\begin{Bmatrix} x_1 \\ x_2 \\ x_3 \end{Bmatrix}vmatrix (determinant): abcd=adbc\begin{vmatrix} a & b \\ c & d \end{vmatrix} = ad - bcVmatrix (norm): 1234\begin{Vmatrix} 1 & 2 \\ 3 & 4 \end{Vmatrix}matrix (no delimiters): abcd\begin{matrix} a & b \\ c & d \end{matrix}

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)A = \begin{pmatrix} 1 & 2 \\ 3 & 4 \end{pmatrix} is invertible.The general form is (abcd)\begin{pmatrix} a & b \\ c & d \end{pmatrix} where adbc0ad - bc \neq 0.Matrix equation: (2113)(xy)=(57)\begin{pmatrix} 2 & 1 \\ 1 & 3 \end{pmatrix} \begin{pmatrix} x \\ y \end{pmatrix} = \begin{pmatrix} 5 \\ 7 \end{pmatrix}
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: A=(a11a12a1na21a22a2nam1am2amn)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}Column vector: x=(x1x2x3xn)\mathbf{x} = \begin{pmatrix} x_1 \\ x_2 \\ x_3 \\ \vdots \\ x_n \end{pmatrix}Row vector: yT=(y1y2y3yn)\mathbf{y}^T = \begin{pmatrix} y_1 & y_2 & y_3 & \cdots & y_n \end{pmatrix}

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

General matrix with dots: [a11a12a1na21a22a2nam1am2amn]\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=[d1000d2000dn]D = \begin{bmatrix} d_1 & 0 & \cdots & 0 \\ 0 & d_2 & \ddots & \vdots \\ \vdots & \ddots & \ddots & 0 \\ 0 & \cdots & 0 & d_n \end{bmatrix}

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: I3=(100010001)I_3 = \begin{pmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \end{pmatrix}Zero matrix: 03×3=(000000000)\mathbf{0}_{3 \times 3} = \begin{pmatrix} 0 & 0 & 0 \\ 0 & 0 & 0 \\ 0 & 0 & 0 \end{pmatrix}Ones matrix: 12×3=(111111)\mathbf{1}_{2 \times 3} = \begin{pmatrix} 1 & 1 & 1 \\ 1 & 1 & 1 \end{pmatrix}

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=(u11u12u13u140u22u23u2400u33u34000u44)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=(l11000l21l2200l31l32l330l41l42l43l44)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}Tridiagonal: T=(a1b100c1a2b200c2a3b300c3a4)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}

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 column alignments (center, right, left): centerrightlefta+b12.34xyzc5.6pqrs\begin{array}{crl} \text{center} & \text{right} & \text{left} \\ a + b & 12.34 & xyz \\ c & 5.6 & pqrs \end{array}Array with vertical lines and horizontal rule: [12345678]\left[\begin{array}{c|cc|c} 1 & 2 & 3 & 4 \\ \hline 5 & 6 & 7 & 8 \end{array}\right]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

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 2x2 block matrix: M=(ABCD)M = \begin{pmatrix} A & B \\ C & D \end{pmatrix}Block matrix with dividing lines: [ABCD]\left[\begin{array}{c|c} A & B \\ \hline C & D \end{array}\right]Mixed size blocks (2x2 matrix with vector and scalar): (abcdefghi)\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}

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: [12364561578924]\left[\begin{array}{ccc|c} 1 & 2 & 3 & 6 \\ 4 & 5 & 6 & 15 \\ 7 & 8 & 9 & 24 \end{array}\right]Row reduction example: [121321371320]R22R1[121305511320]\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: [abe10cdf01]\left[\begin{array}{cc|c|cc} a & b & e & 1 & 0 \\ c & d & f & 0 & 1 \end{array}\right]

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)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}Matrix transpose: AT=(123456)T=(142536)A^T = \begin{pmatrix} 1 & 2 & 3 \\ 4 & 5 & 6 \end{pmatrix}^T = \begin{pmatrix} 1 & 4 \\ 2 & 5 \\ 3 & 6 \end{pmatrix}2x2 matrix inverse formula: A1=(abcd)1=1adbc(dbca)A^{-1} = \begin{pmatrix} a & b \\ c & d \end{pmatrix}^{-1} = \frac{1}{ad-bc} \begin{pmatrix} d & -b \\ -c & a \end{pmatrix}

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)=abcd=adbc\det(A) = \begin{vmatrix} a & b \\ c & d \end{vmatrix} = ad - bc3x3 determinant: a11a12a13a21a22a23a31a32a33\begin{vmatrix} a_{11} & a_{12} & a_{13} \\ a_{21} & a_{22} & a_{23} \\ a_{31} & a_{32} & a_{33} \end{vmatrix}Trace example: tr(521374689)=5+7+9=21\text{tr}\begin{pmatrix} 5 & 2 & 1 \\ 3 & 7 & 4 \\ 6 & 8 & 9 \end{pmatrix} = 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) rotates vectors by angle θ\theta.The Pauli matrices are σx=(0110)\sigma_x = \left(\begin{smallmatrix} 0 & 1 \\ 1 & 0 \end{smallmatrix}\right), σy=(0ii0)\sigma_y = \left(\begin{smallmatrix} 0 & -i \\ i & 0 \end{smallmatrix}\right), and σz=(1001)\sigma_z = \left(\begin{smallmatrix} 1 & 0 \\ 0 & -1 \end{smallmatrix}\right).

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 3Row 1a11a12a13Row 2a21a22a23Row 3a31a32a33\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}Correlation matrix example: R=XYZX1.000.850.42Y0.851.000.67Z0.420.671.00R = \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}

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): (100020003)\begin{pmatrix} \color{red}1 & 0 & 0 \\ 0 & \color{red}2 & 0 \\ 0 & 0 & \color{red}3 \end{pmatrix}Boxed identity matrix elements: (100010001)\begin{pmatrix} \boxed{1} & 0 & 0 \\ 0 & \boxed{1} & 0 \\ 0 & 0 & \boxed{1} \end{pmatrix}Matrix equation with labels: (2113)A(xy)x=(57)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}}Annotated matrix: (a11a12a13a21a22a23a31a32a33)row 1row 2row 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}

Common Pitfalls and Solutions

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.
Problem: Numbers don’t align properly in columns.Solution:
  1. Use array with explicit alignment: {rrr} for right-aligned
  2. For decimals, use the siunitx package with S columns
  3. Add spacing with \phantom{} for consistent widths
Problem: Large matrices extend beyond margins.Solutions:
  1. Use \small or \footnotesize before the matrix
  2. Use bmatrix*}[r] from mathtools for right-aligned entries
  3. Split into block matrices
  4. Consider using array environment with custom column spacing
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:
  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}

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
Next steps:
LaTeX Cloud Studio tip: Use our real-time preview feature to instantly see how your matrices render. No compilation wait time needed!