## LaTeX forum ⇒ Text Formatting ⇒ Matrix Alignment Error

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
knip
Posts: 2
Joined: Mon Mar 11, 2013 4:42 pm

### Matrix Alignment Error

I didn't understand why the following code works.
\begin{tabular}{l|lllllllllll|}
& (j-1)(k-j) & (j-1)(k-j-1) & (j-1)(k-j-2) & \dots & j-1 & 0 & - & - & - & \dots & - \\
& (j-2)(k-j+1) & (j-2)(k-j) & (j-1)(k-j-1) & \dots & \dots & j-2 & 0 & - & - & \dots & - \\
& \vdots & \vdots & \vdots & \dots & \dots & \dots & \dots & 0 & - & \dots & - \\
H = &2(k-3) & 2(k-4) & 2(k-5) & \dots & \dots & \dots & \dots & 2 & 0 & - & - \\
&(k-2) & (k-3) & (k-4) & \dots & \dots & \dots & \dots & \dots & 1 & 0 & - \\
&0 & 0 & 0 & \dots & \dots & \dots & \dots & \dots & \dots & \dots & 0 \\
\end{tabular}


And otherwise using the matrix environment I got this error
Extra alignment tab has been changed to \cr.

$$H = \begin{bmatrix} (j-1)(k-j) & (j-1)(k-j-1) & (j-1)(k-j-2) & \dots & j-1 & 0 & - & - & - & \dots & - \\ (j-2)(k-j+1) & (j-2)(k-j) & (j-1)(k-j-1) & \dots & \dots & j-2 & 0 & - & - & \dots & - \\ \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & 0 & - & \dots & - \\ 2(k-3) & 2(k-4) & 2(k-5) & \dots & \dots & \dots & \dots & 2 & 0 & - & - \\ (k-2) & (k-3) & (k-4) & \dots & \dots & \dots & \dots & \dots & 1 & 0 & - \\ 0 & 0 & 0 & \dots & \dots & \dots & \dots & \dots & \dots & \dots & 0 \\ \end{bmatrix}$$


thank you guys for your help

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

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

### Matrix Alignment Error

Please always prepare a self-contained and minimal example to give an adequate problem description. Otherwise it is nearly impossible to comprehend a problem and a thread may be left orphaned. People are rarely motivated to build such an example just for testing possible solutions.

The matrix environment that comes from amsmath uses internally the MaxMatrixCols counter. This counter is set to 10 by default. You have to increase it correspondingly.
\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage{geometry}
\usepackage{mathtools}  % loads »amamsth«

\setcounter{MaxMatrixCols}{11}  % <<< This is your set screw

\begin{document}
$H = \begin{bmatrix} (j-1)(k-j) & (j-1)(k-j-1) & (j-1)(k-j-2) & \dots & j-1 & 0 & - & - & - & \dots & - \\ (j-2)(k-j+1) & (j-2)(k-j) & (j-1)(k-j-1) & \dots & \dots & j-2 & 0 & - & - & \dots & - \\ \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & 0 & - & \dots & - \\ 2(k-3) & 2(k-4) & 2(k-5) & \dots & \dots & \dots & \dots & 2 & 0 & - & - \\ (k-2) & (k-3) & (k-4) & \dots & \dots & \dots & \dots & \dots & 1 & 0 & - \\ 0 & 0 & 0 & \dots & \dots & \dots & \dots & \dots & \dots & \dots & 0 \\ \end{bmatrix}$
\end{document}

Unfortunately this is described only in a footnote in Section 4.1 of the amsmath manual.

Remarks:

• Do not use $$…$$ to create unnumbered displayed equations. It causes several effects that are mostly not wanted. The correct LaTeX syntax is $…$ (see above code).

Best regards and welcome to the board
Thorsten
LaTeX Community Moderator

¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1