[Tex/LaTex] How to add a matrix to a LaTeX document

math-modematrices

How do we add a matrix to a LaTeX document?

Best Answer

Ash's answer typesets the matrix inline with the text. A (perhaps) nicer way to do this is to use the smallmatrix environment in the amsmath package. Add to the document preamble:

\usepackage{amsmath}

And then you can do:

$M = \begin{smallmatrix} a&b\\ c&d \end{smallmatrix}$

If you want to bracket the matrix you can also do:

$M = \left( \begin{smallmatrix} a&b\\ c&d \end{smallmatrix} \right)$

The amsmath package also offers the shortcut matrix environments which default to centered alignment for their columns:

  • matrix: unbracketed matrix
  • pmatrix: matrix surrounded by parentheses
  • bmatrix: matrix surrounded by square brackets
  • vmatrix: matrix surrounded by single vertical lines
  • Vmatrix: matrix surrounded by double vertical lines

This info is found in "The LaTeX Companion", and the amsmath manual section 4.

Related Question