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?

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

Recommended reading 2024:

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

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

Post 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 46570 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
Post Reply