> ## Documentation Index
> Fetch the complete documentation index at: https://resources.latex-cloud-studio.com/llms.txt
> Use this file to discover all available pages before exploring further.

# LaTeX Matrix Tutorial - pmatrix, bmatrix, vmatrix, and More

> Learn how to write a matrix in LaTeX with pmatrix, bmatrix, vmatrix, smallmatrix, augmented matrices, and block matrices using copy-paste examples.

If you want to create a matrix in LaTeX, the usual answer is to load `amsmath` and use `pmatrix` or `bmatrix`.

Use `pmatrix` for parentheses, `bmatrix` for square brackets, `vmatrix` for determinants, and `smallmatrix` for inline math. When you need vertical separators for an augmented matrix or custom alignment, switch to `array`.

This guide starts with the common matrix environments, then covers augmented matrices, block matrices, spacing, and alignment.

<Info>
  **Quick answer**:

  ```latex theme={null}
  \usepackage{amsmath}

  \[
  A = \begin{pmatrix}
  1 & 2 \\
  3 & 4
  \end{pmatrix}
  \]
  ```

  Use `pmatrix` for `( )`, `bmatrix` for `[ ]`, and `vmatrix` for determinants.

  **Package required**: Most matrix environments need `\usepackage{amsmath}`. Some advanced layouts also use `array` or `mathtools`.

  **Related topics**: [Mathematical equations](/learn/latex/mathematics/equations) | [Subscripts & superscripts](/learn/latex/mathematics/subscripts-superscripts) | [Brackets & parentheses](/learn/latex/mathematics/brackets-parentheses) | [LaTeX symbols](/learn/latex/mathematics/symbols)

  **Last updated**: April 2026 | **Reading time**: 15 min | **Difficulty**: Beginner to Intermediate
</Info>

## 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

<Accordion title="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:

  ```latex theme={null}
  % 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)
</Accordion>

<Accordion title="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:

  ```latex theme={null}
  \[
  \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
</Accordion>

<Accordion title="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:**

  ```latex theme={null}
  \documentclass{article}
  \usepackage{amsmath}
  ```

  Without amsmath, you'd be limited to the basic `array` environment with manual delimiter management.
</Accordion>

<Accordion title="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**

  ```latex theme={null}
  \left[\begin{array}{rr}
  1.2 & 345.6 \\
  12.34 & 5.6
  \end{array}\right]
  ```

  **Solution 2: Use siunitx for decimal alignment**

  ```latex theme={null}
  \usepackage{siunitx}
  \begin{array}{SS}
  1.2 & 345.6 \\
  12.34 & 5.6
  \end{array}
  ```

  **Solution 3: Use phantom spacing**

  ```latex theme={null}
  \phantom{0}1.2  % Adds invisible space
  ```
</Accordion>

<Accordion title="How do I create a small inline matrix in LaTeX?">
  For **matrices within text paragraphs**, use the `smallmatrix` environment:

  ```latex theme={null}
  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.
</Accordion>

<Accordion title="What does the array column specifier mean in LaTeX matrices?">
  **Column specifiers** define how each column is formatted:

  | Specifier | Alignment        | Example  |
  | --------- | ---------------- | -------- |
  | `l`       | Left             | `{lll}`  |
  | `c`       | Center           | `{ccc}`  |
  | `r`       | Right            | `{rrr}`  |
  | `\|`      | Vertical line    | `{c\|c}` |
  | `@{text}` | Custom separator | `@{,}`   |

  Example with vertical line:

  ```latex theme={null}
  \begin{array}{cc|c}
  1 & 2 & 5 \\
  3 & 4 & 11
  \end{array}
  ```
</Accordion>

<Accordion title="How do I calculate and display a determinant in LaTeX?">
  Use the `vmatrix` environment for **determinant notation** with vertical bar delimiters:

  ```latex theme={null}
  \det(A) = \begin{vmatrix}
  a & b \\
  c & d
  \end{vmatrix} = ad - bc
  ```

  For 3×3 matrices:

  ```latex theme={null}
  \begin{vmatrix}
  a_{11} & a_{12} & a_{13} \\
  a_{21} & a_{22} & a_{23} \\
  a_{31} & a_{32} & a_{33}
  \end{vmatrix}
  ```
</Accordion>

<Accordion title="How do I increase spacing between elements in a LaTeX matrix?">
  Use `\renewcommand{\arraystretch}{factor}` to control **matrix element spacing**:

  ```latex theme={null}
  % 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.
</Accordion>

## Basic Matrix Environments

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

### Matrix Environment Overview

<Tabs>
  <Tab title="Code">
    <CodeGroup>
      ```latex all-matrix-types.tex theme={null}
      \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}
      ```
    </CodeGroup>
  </Tab>

  <Tab title="Rendered output">
    <Card title="Rendered output" icon="eye">
      **pmatrix:** $\begin{pmatrix} a & b \\ c & d \end{pmatrix}$

      **bmatrix:** $\begin{bmatrix} 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 9 \end{bmatrix}$

      **Bmatrix:** $\begin{Bmatrix} x_1 \\ x_2 \\ x_3 \end{Bmatrix}$

      **vmatrix (determinant):** $\begin{vmatrix} a & b \\ c & d \end{vmatrix} = ad - bc$

      **Vmatrix (norm):** $\begin{Vmatrix} 1 & 2 \\ 3 & 4 \end{Vmatrix}$

      **matrix (no delimiters):** $\begin{matrix} a & b \\ c & d \end{matrix}$
    </Card>
  </Tab>
</Tabs>

### Matrix Environment Summary Table

| Environment | Delimiters | Common Use                           | Example        |
| ----------- | ---------- | ------------------------------------ | -------------- |
| `matrix`    | None       | Building block for custom delimiters | Basic array    |
| `pmatrix`   | ( )        | General matrices, transformations    | Linear algebra |
| `bmatrix`   | \[ ]       | General matrices, data tables        | Numerical data |
| `Bmatrix`   | { }        | Set notation, systems                | Set theory     |
| `vmatrix`   | \| \|      | Determinants                         | det(A)         |
| `Vmatrix`   | \|\| \|\|  | Norms, magnitudes                    | \|\|v\|\|      |

## Creating Your First Matrix

### Simple 2×2 Matrix

<Tabs>
  <Tab title="Code">
    <CodeGroup>
      ```latex simple-matrix.tex theme={null}
      \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}
      ```
    </CodeGroup>
  </Tab>

  <Tab title="Rendered output">
    <Card title="Rendered output" icon="eye">
      The matrix $A = \begin{pmatrix} 1 & 2 \\ 3 & 4 \end{pmatrix}$ is invertible.

      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}$
    </Card>
  </Tab>
</Tabs>

<Tip>
  **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 `\[...\]`)
</Tip>

## Matrix Elements and Structure

### Matrix with Subscripts

<Tabs>
  <Tab title="Code">
    <CodeGroup>
      ```latex matrix-subscripts.tex theme={null}
      \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}
      ```
    </CodeGroup>
  </Tab>

  <Tab title="Rendered output">
    <Card title="Rendered output" icon="eye">
      **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}$

      **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}$
    </Card>
  </Tab>
</Tabs>

### Using Dots in Matrices

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

<Tabs>
  <Tab title="Code">
    <CodeGroup>
      ```latex matrix-dots.tex theme={null}
      \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}
      ```
    </CodeGroup>
  </Tab>

  <Tab title="Rendered output">
    <Card title="Rendered output" icon="eye">
      **General matrix with dots:**
      $\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}$
    </Card>
  </Tab>
</Tabs>

## Special Matrix Types

### Identity and Zero Matrices

<Tabs>
  <Tab title="Code">
    <CodeGroup>
      ```latex special-matrices.tex theme={null}
      \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}
      ```
    </CodeGroup>
  </Tab>

  <Tab title="Rendered output">
    <Card title="Rendered output" icon="eye">
      **3×3 Identity matrix:** $I_3 = \begin{pmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 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}$
    </Card>
  </Tab>
</Tabs>

### Triangular Matrices

<Tabs>
  <Tab title="Code">
    <CodeGroup>
      ```latex triangular-matrices.tex theme={null}
      \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}
      ```
    </CodeGroup>
  </Tab>

  <Tab title="Rendered output">
    <Card title="Rendered output" icon="eye">
      **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}$

      **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}$
    </Card>
  </Tab>
</Tabs>

## Arrays - The Foundation of Matrices

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

### Basic Array Usage

<Tabs>
  <Tab title="Code">
    <CodeGroup>
      ```latex array-basics.tex theme={null}
      \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}
      ```
    </CodeGroup>
  </Tab>

  <Tab title="Rendered output">
    <Card title="Rendered output" icon="eye">
      **Array with column alignments (center, right, left):**
      $\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:**
      $\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}$
    </Card>
  </Tab>
</Tabs>

### Array Column Specifiers

| Specifier    | Alignment | Description                                 |                               |
| ------------ | --------- | ------------------------------------------- | ----------------------------- |
| `l`          | Left      | Left-aligned column                         |                               |
| `c`          | Center    | Centered column                             |                               |
| `r`          | Right     | 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

<Tabs>
  <Tab title="Code">
    <CodeGroup>
      ```latex block-matrices.tex theme={null}
      \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}
      ```
    </CodeGroup>
  </Tab>

  <Tab title="Rendered output">
    <Card title="Rendered output" icon="eye">
      **Simple 2x2 block matrix:** $M = \begin{pmatrix} A & B \\ C & D \end{pmatrix}$

      **Block matrix with dividing lines:**
      $\left[\begin{array}{c|c} A & B \\ \hline C & D \end{array}\right]$

      **Mixed size blocks (2x2 matrix with vector and scalar):**
      $\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}$
    </Card>
  </Tab>
</Tabs>

## Augmented Matrices

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

<Tabs>
  <Tab title="Code">
    <CodeGroup>
      ```latex augmented-matrices.tex theme={null}
      \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}
      ```
    </CodeGroup>
  </Tab>

  <Tab title="Rendered output">
    <Card title="Rendered output" icon="eye">
      **Augmented matrix for system of equations:**
      $\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]$
    </Card>
  </Tab>
</Tabs>

## Matrix Operations

### Basic Operations Notation

<Tabs>
  <Tab title="Code">
    <CodeGroup>
      ```latex matrix-operations.tex theme={null}
      \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}
      ```
    </CodeGroup>
  </Tab>

  <Tab title="Rendered output">
    <Card title="Rendered output" icon="eye">
      **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}$

      **Matrix transpose:**
      $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:**
      $A^{-1} = \begin{pmatrix} a & b \\ c & d \end{pmatrix}^{-1} = \frac{1}{ad-bc} \begin{pmatrix} d & -b \\ -c & a \end{pmatrix}$
    </Card>
  </Tab>
</Tabs>

### Determinants and Traces

<Tabs>
  <Tab title="Code">
    <CodeGroup>
      ```latex determinants.tex theme={null}
      \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}
      ```
    </CodeGroup>
  </Tab>

  <Tab title="Rendered output">
    <Card title="Rendered output" icon="eye">
      **2x2 determinant calculation:**
      $\det(A) = \begin{vmatrix} a & b \\ c & d \end{vmatrix} = ad - bc$

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

      **Trace example:** $\text{tr}\begin{pmatrix} 5 & 2 & 1 \\ 3 & 7 & 4 \\ 6 & 8 & 9 \end{pmatrix} = 5 + 7 + 9 = 21$
    </Card>
  </Tab>
</Tabs>

## Small Inline Matrices

For matrices within text, use the `smallmatrix` environment:

<Tabs>
  <Tab title="Code">
    <CodeGroup>
      ```latex inline-matrices.tex theme={null}
      \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}
      ```
    </CodeGroup>
  </Tab>

  <Tab title="Rendered output">
    <Card title="Rendered output" icon="eye">
      The rotation matrix $\left(\begin{smallmatrix} \cos\theta & -\sin\theta \\ \sin\theta & \cos\theta \end{smallmatrix}\right)$ rotates vectors by angle $\theta$.

      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)$.
    </Card>
  </Tab>
</Tabs>

## Advanced Techniques

### Matrices with Labels

<Tabs>
  <Tab title="Code">
    <CodeGroup>
      ```latex labeled-matrices.tex theme={null}
      \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}
      ```
    </CodeGroup>
  </Tab>

  <Tab title="Rendered output">
    <Card title="Rendered output" icon="eye">
      **Matrix with row and column 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}$

      **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}$
    </Card>
  </Tab>
</Tabs>

### Matrix Decorations

<Tabs>
  <Tab title="Code">
    <CodeGroup>
      ```latex matrix-decorations.tex theme={null}
      \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}
      ```
    </CodeGroup>
  </Tab>

  <Tab title="Rendered output">
    <Card title="Rendered output" icon="eye">
      **Highlighted diagonal elements (colored):**
      $\begin{pmatrix} \color{red}1 & 0 & 0 \\ 0 & \color{red}2 & 0 \\ 0 & 0 & \color{red}3 \end{pmatrix}$

      **Boxed identity matrix elements:**
      $\begin{pmatrix} \boxed{1} & 0 & 0 \\ 0 & \boxed{1} & 0 \\ 0 & 0 & \boxed{1} \end{pmatrix}$

      **Matrix equation with labels:**
      $\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}$
    </Card>
  </Tab>
</Tabs>

## Common Pitfalls and Solutions

<Accordion title="My matrix delimiters are too small">
  **Problem**: Parentheses/brackets don't scale with matrix size.

  **Solution**: Use `\left` and `\right` with array:

  ```latex theme={null}
  $\left(\begin{array}{cc}
  a & b \\
  c & d
  \end{array}\right)$
  ```

  Or use the pre-defined environments like `pmatrix` which handle this automatically.
</Accordion>

<Accordion title="Alignment issues in matrices">
  **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
</Accordion>

<Accordion title="Matrix too wide for page">
  **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
</Accordion>

<Accordion title="Spacing between matrix elements">
  **Problem**: Elements too cramped or too spread out.

  **Solution**: Adjust array stretch:

  ```latex theme={null}
  \renewcommand{\arraystretch}{1.5} % 1.5x normal spacing
  \begin{pmatrix}
  a & b \\
  c & d
  \end{pmatrix}
  ```
</Accordion>

## Best Practices

<Tip>
  **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
</Tip>

## Package Recommendations

### Essential Packages

| Package      | Purpose                   | Key Features                   |
| ------------ | ------------------------- | ------------------------------ |
| `amsmath`    | Basic matrix environments | All standard matrix types      |
| `mathtools`  | Extended matrix features  | Starred versions, more options |
| `array`      | Custom column types       | Full control over layout       |
| `siunitx`    | Numeric alignment         | Decimal alignment in matrices  |
| `blkarray`   | Block arrays              | Labels and blocks              |
| `nicematrix` | Enhanced matrices         | Many advanced features         |

### Loading Order

```latex theme={null}
\usepackage{amsmath}     % Load first
\usepackage{mathtools}   % Extends amsmath
\usepackage{array}       % For custom columns
\usepackage{siunitx}     % For numeric columns
```

## Quick Reference Card

### Matrix Environments Summary

```latex theme={null}
% 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

```latex theme={null}
% 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}
```

## Practice in LaTeX Cloud Studio

<CardGroup cols={2}>
  <Card title="Try matrices in the editor" icon="cloud" href="https://app.latex-cloud-studio.com/?utm_source=resources&utm_medium=card&utm_campaign=docs_open_app&utm_content=matrices_open_app">
    Test `pmatrix`, `bmatrix`, and augmented matrices in a live document and inspect the rendered output directly.
  </Card>

  <Card title="Tables vs matrices" icon="table-cells" href="/learn/latex/tables/creating-tables?utm_source=resources&utm_medium=related_guide&utm_campaign=docs_open_app&utm_content=matrices_tables_guide">
    Jump here when you need structured data layout rather than mathematical notation.
  </Card>
</CardGroup>

***

## Related Topics

<CardGroup cols={2}>
  <Card title="Subscripts & Superscripts" icon="subscript" href="/learn/latex/mathematics/subscripts-superscripts">
    Matrix element notation with indices
  </Card>

  <Card title="Mathematical Equations" icon="equals" href="/learn/latex/mathematics/equations">
    Multi-line equations and alignment
  </Card>

  <Card title="LaTeX Symbols Reference" icon="list" href="/learn/reference/symbols">
    Greek letters and math operators
  </Card>

  <Card title="Advanced Mathematics" icon="square-root-variable" href="/learn/latex/mathematics/advanced-math">
    Complex mathematical notation
  </Card>
</CardGroup>

## 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

<Info>
  **Next steps**:

  * Learn about [Creating figures and images](/learn/latex/figures/inserting-images)
  * Explore [Advanced mathematics](/learn/latex/mathematics/advanced-math)
  * Master [Table creation](/learn/latex/tables/creating-tables) for data presentation
</Info>

<Tip>
  **LaTeX Cloud Studio** tip: Use our real-time preview feature to instantly see how your matrices render. No compilation wait time needed!
</Tip>
