[Tex/LaTex] Creating 6×6 matrix using bmatrix

math-modematrices

I'm trying to make a 6×6 matrix with the following text:

\begin{gather}
\dfrac{d}{dt}
\begin{bmatrix}
    y \\ \dot{y} \\ a_{M} \\ \lambda_{T} \\ \lambda_{D} \\ a_{T}
\end{bmatrix}
=
\begin{bmatrix}
    0 && 1 && 0 && 0 && 0 && 0 \\
    0 && 1 && 0 && 0 && 0 && 0 \\
    0 && 1 && 0 && 0 && 0 && 0 \\
    0 && 1 && 0 && 0 && 0 && 0 \\
    0 && 1 && 0 && 0 && 0 && 0 \\
    0 && 1 && 0 && 0 && 0 && 0 \\
\end{bmatrix}
\end{gather}

And I get the following error:

Extra alignment tab has been changed to \cr. \endtemplace \end{gather}.

Whats weird is when i check the same code for 5×5 it worked.

Thank you.

Best Answer

The problem is that only up to ten columns are supported by default in matrix-like constructions, but the number can be increased with

\setcounter{MaxMatrixCols}{20}

(twenty columns should be sufficient).

However, if you want to have wider separation between columns, set it properly, not by adding dummy columns.

\documentclass{article}
\usepackage{amsmath}

\begin{document}

\begin{equation}
\frac{d}{dt}
\begin{bmatrix}
    y \\ \dot{y} \\ a_{M} \\ \lambda_{T} \\ \lambda_{D} \\ a_{T}
\end{bmatrix}
=
\setlength{\arraycolsep}{2\arraycolsep}% this change is local
\begin{bmatrix}
    0 & 1 & 0 & 0 & 0 & 0 \\
    0 & 1 & 0 & 0 & 0 & 0 \\
    0 & 1 & 0 & 0 & 0 & 0 \\
    0 & 1 & 0 & 0 & 0 & 0 \\
    0 & 1 & 0 & 0 & 0 & 0 \\
    0 & 1 & 0 & 0 & 0 & 0 \\
\end{bmatrix}
\end{equation}

\begin{equation}
\frac{d}{dt}
\begin{bmatrix}
    y \\ \dot{y} \\ a_{M} \\ \lambda_{T} \\ \lambda_{D} \\ a_{T}
\end{bmatrix}
=
\begin{bmatrix}
    0 & 1 & 0 & 0 & 0 & 0 \\
    0 & 1 & 0 & 0 & 0 & 0 \\
    0 & 1 & 0 & 0 & 0 & 0 \\
    0 & 1 & 0 & 0 & 0 & 0 \\
    0 & 1 & 0 & 0 & 0 & 0 \\
    0 & 1 & 0 & 0 & 0 & 0 \\
\end{bmatrix}
\end{equation}

\end{document}

I'd much prefer the latter.

enter image description here

Related Question