14

I have a 3x12 matrix I'd like to input into my LaTeX (with amsmath) document but LaTeX seems to choke when the matrix gets larger than 3x10:

\begin{equation}
\textbf{e} = 
\begin{bmatrix} 
1&1&1&1&0&0&0&0&-1&-1&-1&-1\\
1&-1&0&0&1&1&-1&-1&0&0&1&-1\\
0&0&1&-1&1&-1&1&-1&1&-1&0&0
\end{bmatrix}
\end{equation}

The error: Extra alignment tab has been changed to \cr. tells me that I have more & than the bmatrix environment can handle. Is there a proper way to handle this? It also seems that the alignment for 1's and the -1's are different, is that also expected of the bmatrix?

Smi
  • 13,850
  • 9
  • 56
  • 64
Hooked
  • 84,485
  • 43
  • 192
  • 261

4 Answers4

21

From the amsmath documentation (texdoc amsmath):

The amsmath package provides some environments for matrices beyond the basic array environment of LATEX. The pmatrix, bmatrix, Bmatrix, vmatrix and Vmatrix have (respectively) ( ), [ ], { }, | |, and ∥ ∥ delimiters built in. For naming consistency there is a matrix environment sans delimiters. This is not entirely redundant with the array environment; the matrix environments all use more economical horizontal spacing than the rather prodigal spacing of the array environment. Also, unlike the array environment, you don’t have to give column specifications for any of the matrix environments; by default you can have up to 10 centered columns. (If you need left or right alignment in a column or other special formats you must resort to array.)

i.e. bmatrix defaults to a 10 column maximum.

A footnote adds

More precisely: The maximum number of columns in a matrix is determined by the counter MaxMatrixCols (normal value = 10), which you can change if necessary using LATEX’s \setcounter or \addtocounter commands.

Scott Wales
  • 11,336
  • 5
  • 33
  • 30
  • Wonderful! This was exactly what I was looking for, I didn't realize one could change the column maximum. As for the right-alignment, I've since found a nice workaround that still allows the bmatrix command - I'll post it in my own solution. – Hooked May 07 '10 at 15:51
  • I had exactly the same problem, good question! I was computing character tables in representation theory and even with quite small groups you end up easily with large matrices. Thanks for posting/answering this question! – Patrick Da Silva Mar 25 '12 at 18:13
6

If you came to this page looking for the exact command (thanks to Scott Wales for the answer), you want this in your preamble:

\setcounter{MaxMatrixCols}{20}

Where you can replace 20 with the maximum number of columns you want.

Sophie Weigle
  • 61
  • 1
  • 1
1

The answer by Scott is correct, but I've since learned you can override the alignment. Taken from http://texblog.net/latex-archive/maths/matrix-align-left-right/

\makeatletter
\renewcommand*\env@matrix[1][c]{\hskip -\arraycolsep
  \let\@ifnextchar\new@ifnextchar
  \array{*\c@MaxMatrixCols #1}}
\makeatother

Now allows the command:

\begin{bmatrix}[r] ....

to have right-alignment!

Hooked
  • 84,485
  • 43
  • 192
  • 261
  • I believe you can also just use `bmatrix*` environment from the `mathtools` package to achieve the same thing, at least according to the wikibook: http://en.wikibooks.org/wiki/LaTeX/Mathematics#Matrices_and_arrays – Nick Felt Nov 25 '12 at 00:34
1

Instead of a bmatrix you can use +bmatrix from the tabularray package:

\documentclass{article}

\usepackage{tabularray}
\UseTblrLibrary{amsmath}

\begin{document}

\begin{equation}
\textbf{e} = 
\begin{+bmatrix} 
1&1&1&1&0&0&0&0&-1&-1&-1&-1\\
1&-1&0&0&1&1&-1&-1&0&0&1&-1\\
0&0&1&-1&1&-1&1&-1&1&-1&0&0
\end{+bmatrix}
\end{equation}

\end{document}

enter image description here