Text FormattingMatrix Alignment Error

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

Matrix Alignment Error

Post by knip »

I didn't understand why the following code works.

Code: Select all

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

Code: Select all

$$
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

Recommended reading 2024:

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

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

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

Matrix Alignment Error

Post by localghost »

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.

Code: Select all

\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).
Further reading:

Best regards and welcome to the board
Thorsten
Post Reply