Skip to content

Free tool

LaTeX Matrix Generator

Set the size, fill the cells and copy LaTeX matrix code that compiles. Choose the brackets, add the line of an augmented matrix, and check the result in the live preview. No account needed.

1. Set the size and fill the cells

Rows2
Columns2

Cells take any LaTeX maths, such as \frac{1}{2}, a_{ij} or \cdots. You can paste cells from a spreadsheet into any cell.

2. Choose the brackets

Preview

Loading the preview…

LaTeX code

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

Needs \usepackage{amsmath} in the preamble.

The preview is drawn by MathJax in your browser. pdfLaTeX sets the final fonts and spacing.

Compile it

Check the matrix in a real PDF

LaTeX Cloud Studio opens a starter article in the browser with TeX Live and amsmath already loaded. Paste the matrix into main.tex and compile it.

How the generated code works

The matrix environments come from the amsmath package, so the preamble needs \usepackage{amsmath}. Inside the environment, & separates the entries of a row and \\ ends the row. The environment name sets the brackets: pmatrix, bmatrix, Bmatrix, vmatrix, Vmatrix or plain matrix.

A matrix is maths, so it must sit in maths mode: between \[ and \], inside $…$, or in an equation. Outside maths mode LaTeX stops with "Missing $ inserted".

An augmented matrix needs a vertical line, which the amsmath environments do not offer. The generator writes an array with the line in its column specification and scales the brackets with \left and \right. That form needs no package.

When the matrix does not compile

  • Environment pmatrix undefined: the preamble is missing \usepackage{amsmath}.
  • Missing $ inserted: the matrix is outside maths mode.
  • Extra alignment tab has been changed to \cr: a row has more entries than the others, or the matrix has more than 10 columns. For wide matrices add \setcounter{MaxMatrixCols}{20} to the preamble.

More on matrices

Questions

How do I write a matrix in LaTeX?

Load amsmath and use a matrix environment in maths mode, for example \begin{pmatrix} a & b \\ c & d \end{pmatrix}. An & separates the entries of a row and \\ ends the row.

What is the difference between pmatrix, bmatrix and vmatrix?

Only the brackets differ. pmatrix draws round parentheses, bmatrix square brackets, Bmatrix curly braces, vmatrix single bars for a determinant, Vmatrix double bars for a norm, and matrix draws none.

How do I write an augmented matrix?

The amsmath matrix environments cannot draw a vertical line. Use an array with a | in its column specification between \left[ and \right], for example \left[\begin{array}{cc|c} 1 & 2 & 3 \\ 4 & 5 & 6 \end{array}\right]. The generator writes this for you when you tick "Augmented matrix".

Why does a matrix with more than 10 columns fail?

amsmath limits matrices to 10 columns and reports "Extra alignment tab has been changed to \cr". Raise the limit in the preamble with \setcounter{MaxMatrixCols}{20}. The generator stops at 10 columns for that reason.

How do I add dots to a matrix?

Type \cdots for horizontal dots, \vdots for vertical dots and \ddots for diagonal dots in the cells where they belong.

How do I put a small matrix inside a sentence?

Use the smallmatrix environment from amsmath with your own brackets: $\bigl(\begin{smallmatrix} a & b \\ c & d \end{smallmatrix}\bigr)$. The inline wrapper in the generator keeps the full-size matrix, which makes the line taller.