How to write an m⨉n matrix in LaTeX?

A better way to do it, as the TheHe meantioned, is with the amsmath package:

\documentclass{article}
\usepackage{amsmath}
\begin{document}

\[
M=
  \begin{bmatrix}
    1 & 2 & 3 & 4 & 5 \\
    3 & 4 & 5 & 6 & 7
  \end{bmatrix}
\]

\end{document}

The bmatrix environment will give you [] braces. () braces are also very common. They are created with the pmatrix environment. To include a matrix inline, you can write:

$M = \left\[ \begin{smallmatrix} 1 & 2 \\ 3 & 4 \end{smallmatrix} \right\]$

In the example you have, you need the opening line to be

\left[ {\begin{array}{ccccc}

rather than

\left[ {\begin{array}{cc}

When you start with just two cs, you're telling it the matrix only has two columns (and that you want them centered). Then it breaks when you give it data for 5 columns.


if you use the amsmath package, you can chose out of a lot of matrices like pmatrix or bmatrix.

Check out this list at Wikibooks.

Tags:

Matrices