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

Questions and answers about the LaTeX Beginner's Guide
Reader

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

Postby Reader » Wed Oct 06, 2021 5:07 pm

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.
<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?

Recommended reading 2021:

LaTeXguide.org • LaTeX-Cookbook.net
LaTeX Beginner's Guide LaTeX Cookbook
User avatar
Stefan Kottwitz
Site Admin
Posts: 9878
Joined: Mon Mar 10, 2008 9:44 pm

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

Postby Stefan Kottwitz » Sun Oct 24, 2021 9:58 pm

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
matrix.png (9.52 KiB) Viewed 3077 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.
LaTeX.org admin


Return to “LaTeX Beginner's Guide”

Who is online

Users browsing this forum: No registered users and 1 guest