How to create a matrix in LaTeX

We can create a matrix in LaTeX using the array environment, or simplematrix, matrix, pmatrix, bmatrix, vmatrix, and Vmatrix environments via amsmath package. This article provides some examples on how to create a matrix in LaTeX.

Creating a matrix with array

Here are some examples.

  1. unbracketed matrix

    m1

    \[
    M =
    \begin{array}{cc}
    x & y \\
    z & w \\
    \end{array}
    \]
  2. matrix surrounded by square brackets

    m2

    \[
    M =
    \left[ {\begin{array}{cc}
     x & y  \\
     z & w  \\
     \end{array} } \right]
    \]
  3. matrix surrounded by parentheses

    m3

    \[
    M =
    \left( {\begin{array}{cc}
     x & y  \\
     z & w  \\
     \end{array} } \right)
    \]
  4. matrix surrounded by single vertical lines

    m4

    \[
    M =
    \left| {\begin{array}{cc}
     x & y  \\
     z & w  \\
     \end{array} } \right|
    \]

Using amsmath package

Call \usepackage{amsmath} in the preamble, after \documentclass{}.

The amsmath package environment for matrix:

  1. smallmatrix: inline matrix

    m5

    $M = \begin{smallmatrix} x&y\\ z&w \end{smallmatrix}$
    $M = \left( \begin{smallmatrix} x&y\\ z&w \end{smallmatrix}\right)$
  2. matrix: unbracketed matrix

    m6

    $M = \begin{matrix} x&y\\ z&w \end{matrix}$
  3. pmatrix: matrix surrounded by parentheses

    m7

    $M = \begin{pmatrix} x&y\\ z&w \end{pmatrix}$
  4. bmatrix: matrix surrounded by square brackets

    m8

    $M = \begin{bmatrix} x&y\\ z&w \end{bmatrix}$
  5. vmatrix: matrix surrounded by single vertical lines

    m9

    $M = \begin{vmatrix} x&y\\ z&w \end{vmatrix}$
  6. Vmatrix: matrix surrounded by double vertical lines

    m10

    $M = \begin{Vmatrix} x&y\\ z&w \end{Vmatrix}$

Related

This entry was posted in LaTeX and tagged , , , , , , , , , , , . Bookmark the permalink.

4 Responses to How to create a matrix in LaTeX

  1. ufw says:

    Awesome, thanks a lot!

  2. lmods says:

    gracias me ha servido de mucho… thanks

  3. jeanounou says:

    How about a border matrix? How can I write a circle around a letter, like in “copyright” or “registered trademark”? Is it possible to have a circle around all letters (not only C and R)? Thanks.

  4. Selinap says:

    @jeanounou: You can use TikZ (http://en.wikipedia.org/wiki/PGF/TikZ) to put a letter in a circle.

    For example (adapted from here):

    \documentclass{article}
    \usepackage{tikz}
    
    \newcommand*\circleit[1]{%
        \tikz[baseline=(C.base)]\node[draw,circle,inner sep=0.7pt](C) {#1};\!
    }    
    
    \begin{document}
    The letter A in a circle: $\circleit{A}$
    \end{document}

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>