94

I'm using bmatrix environment from the amsmath package, and I'm trying to do something like this:

\documentclass{article}
\usepackage{amsmath}

 \begin{document}
     \begin{equation}
         \begin{bmatrix}
             1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11\\
         \end{bmatrix}
    \end{equation}
 \end{document}

However, pdfLaTeX returns an error: "Extra alignment tab has been changed to \cr", and in the output the extra element is moved to the next row. (If I remove one element, then it works perfectly fine). I guess this means that I've hit some hard limit on the number of tab stops in a matrix. Is there a way to change this?

The elements in the matrix are short and could fit perfectly on a single row.

1

2 Answers 2

124

Googling "10 columns" together with "tex" and "halign" lead me to this document, where it is explained that, e.g.,

\setcounter{MaxMatrixCols}{20}

enables you to use 20 columns.

4
  • 10
    This is documented in the footnote on page 8 of the amsmath manual.
    – Philipp
    Commented Sep 27, 2010 at 12:07
  • 27
    Which leads to the question: Why is there even a hard limit?
    – masher
    Commented Mar 5, 2017 at 6:41
  • 1
    It's worth nothing that, as explained in the document, this line of code should "precede the start of the matrix environment".
    – Sambo
    Commented Nov 30, 2018 at 17:44
  • 3
    Which leads to another question: why is the error so uninformative?
    – Saptam
    Commented Dec 18, 2022 at 13:49
8

Yet another method is to use the array construct from amsmath package.

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

\begin{equation}
\left[ \begin{array}{@{}*{11}{c}@{}}
     1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11\\
\end{array} \right]
\end{equation}

\end{document}

enter image description here

4
  • 3
    If you want to emulate bmatrix, you should use \begin{array}{@{}*{11}{c}@{}}. The *{11}{c} is just a convenient way to avoid counting the number of c's; the important thing is @{} at the sides, to kill the automatically inserted padding.
    – egreg
    Commented Apr 19, 2015 at 15:48
  • 2
    @egreg Many thanks, I was just thinking of adding two \!\! around the array, but your suggestion is much more elegant.
    – AboAmmar
    Commented Apr 19, 2015 at 15:55
  • The bmatrix environment indeed does \hspace{-\arraycolsep} on either ends (it's one of the reasons why the MaxMatrixCols counter is needed).
    – egreg
    Commented Apr 19, 2015 at 16:02
  • 1
    Isn't the array construct native instead of from the amsmath package?
    – L. F.
    Commented Feb 26, 2019 at 11:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .