## LaTeX forum ⇒ LaTeX Beginner's Guide ⇒ How can I write a matrix with more than 10 columns?

### How can I write a matrix with more than 10 columns?

I used the code for Figure 9.34 in Chapter 9, Writing Math Formulas, to write a matrix with the amsmath package.

With a matrix of 11 or more columns I get an error. Here is the example:

\documentclass{article}
\usepackage{amsmath}
\begin{document}
$A = \begin{pmatrix} a_{11} & a_{12} & a_{13} & a_{14} & a_{15} & a_{16} & a_{17} & a_{18} & a_{19} & a_{10} & a_{11} \\ a_{21} & a_{22} & a_{23} & a_{24} & a_{25} & a_{26} & a_{27} & a_{28} & a_{29} & a_{20} & a_{21} \end{pmatrix}$
\end{document}

I get the error:

! Extra alignment tab has been changed to \cr.

l.6 ..._{16} & a_{17} & a_{18} & a_{19} & a_{10} &
a_{11} \\

Is there a limit of 10? How can I have more?

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

Stefan Kottwitz
Posts: 10164
Joined: Mon Mar 10, 2008 9:44 pm

### How can I write a matrix with more than 10 columns?

Internally, amsmath uses an array environment with a number of columns set to MaxMatrixCols. That is a counter, intially set to 10. That's usually enough, but in case we need bigger matrices, we can modify the counter, also globally, by \setcounter{MaxMatrixCols}{<value>}. Here, we set the MaxMatrixCols value to 11, and now it compiles without error:

\documentclass{article}
\usepackage{amsmath}
\setcounter{MaxMatrixCols}{11}
\begin{document}
$A = \begin{pmatrix} a_{11} & a_{12} & a_{13} & a_{14} & a_{15} & a_{16} & a_{17} & a_{18} & a_{19} & a_{10} & a_{11} \\ a_{21} & a_{22} & a_{23} & a_{24} & a_{25} & a_{26} & a_{27} & a_{28} & a_{29} & a_{20} & a_{21} \end{pmatrix}$
\end{document}

We get:

matrix.png (9.52 KiB) Viewed 31706 times

Of course, we can also set it to a higher value. Btw. we had that question here earlier, in the topics Matrix Alignment Error and Problem with creating a matrix.

Stefan

Last bumped by Anonymous on Sun Oct 24, 2021 9:58 pm.