Page 1 of 1

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

Posted: Wed Oct 06, 2021 5:07 pm
by Reader
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:

Code: Select all

\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.
<recently read> \endtemplate

l.6 ..._{16} & a_{17} & a_{18} & a_{19} & a_{10} &
a_{11} \\
Is there a limit of 10? How can I have more?

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

Posted: Sun Oct 24, 2021 9:58 pm
by Stefan Kottwitz
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:

Code: Select all

\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
matrix.png (9.52 KiB) Viewed 60786 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