LaTeX forum ⇒ Text FormattingMatrix 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

Postby knip » Mon Mar 11, 2013 4:47 pm

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

Recommended reading 2021:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Matrix Alignment Error

Postby localghost » Mon Mar 11, 2013 6:28 pm

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

Further reading:



Best regards and welcome to the board
Thorsten
LaTeX Community Moderator
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes


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


Return to “Text Formatting”

Who is online

Users browsing this forum: No registered users and 4 guests