Effortlessly Create a Matrix in Latex: Step-by-Step Guide

  • Context: LaTeX 
  • Thread starter Thread starter ryan88
  • Start date Start date
  • Tags Tags
    Latex Matrix
Click For Summary

Discussion Overview

The discussion revolves around creating matrices in LaTeX, specifically addressing issues related to matrix formatting, error messages, and the use of different environments for matrix creation. Participants share code snippets and seek clarification on best practices and limitations.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • Ryan encounters an error when trying to create a matrix using the bmatrix environment, specifically an "Extra alignment tab" error.
  • Another participant shares a simpler matrix example using the array environment, questioning if there is a maximum number of columns in a matrix.
  • A participant successfully replicates Ryan's matrix code without errors, suggesting that the issue may not be with the code itself.
  • Discussion arises about the maximum number of columns in matrix environments, with a participant mentioning that it is determined by the counter MaxMatrixCols, which defaults to 10 but can be changed.
  • Ryan asks about the advantages of using the bmatrix environment compared to the array environment, prompting responses about alignment control in arrays.
  • One participant expresses a preference for the bmatrix environment but acknowledges the flexibility of the array environment.

Areas of Agreement / Disagreement

Participants do not reach a consensus on the advantages of different matrix environments, and there is uncertainty regarding the maximum number of columns and how to change it. Multiple viewpoints are presented without resolution.

Contextual Notes

Limitations include the potential for misunderstandings regarding LaTeX commands and environments, as well as the specific error messages that may arise from different configurations. The discussion does not resolve the specifics of the error Ryan encountered.

ryan88
Messages
41
Reaction score
0
Hi,

I am trying to produce a matrix in Latex with the following code:
Code:
\begin{bmatrix}
1 & 0 & 0 & 0 & 0 & 0 & 0 & -4 & 1 & 0 & 0 & 0 & 0 & 0 \\
0 & 1 & 0 & 0 & 0 & 0 & 0 & 1 & -4 & 1 & 0 & 0 & 0 & 0 \\
0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 1 & -4 & 1 & 0 & 0 & 0 \\
0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 1 & -4 & 1 & 0 & 0 \\
0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 1 & -4 & 1 & 0 \\
0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 1 & -4 & 1 \\
0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 1 & -4
\end{bmatrix}
But I keep on getting the following error:
Extra alignment tab has been changed to \cr.<recently read> \endtemplate

This error occurs for each row in that matrix.

I would appreciate any help anyone can give,

Thanks,

Ryan
 
Physics news on Phys.org
I create matrices like this

Code:
\begin{equation}

\left[
 \begin{array}{ccc}
   1 & 0 & 0\\
   0 & 1 & 0\\
   0 & 0 & 1
 \end{array}
\right]

\end{equation}
 
I just copied your code into tex and it gives

[tex]\begin{bmatrix}<br /> 1 & 0 & 0 & 0 & 0 & 0 & 0 & -4 & 1 & 0 & 0 & 0 & 0 & 0 \\<br /> 0 & 1 & 0 & 0 & 0 & 0 & 0 & 1 & -4 & 1 & 0 & 0 & 0 & 0 \\<br /> 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 1 & -4 & 1 & 0 & 0 & 0 \\<br /> 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 1 & -4 & 1 & 0 & 0 \\<br /> 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 1 & -4 & 1 & 0 \\<br /> 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 1 & -4 & 1 \\<br /> 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 1 & -4<br /> \end{bmatrix}[/tex]
Is there a maximum of 10 columns in a matrix?

If we try to do it "by hand" (using \begin{array})
[tex]\left[\begin{array}{cccccccccccccc}<br /> 1 & 0 & 0 & 0 & 0 & 0 & 0 & -4 & 1 & 0 & 0 & 0 & 0 & 0 \\<br /> 0 & 1 & 0 & 0 & 0 & 0 & 0 & 1 & -4 & 1 & 0 & 0 & 0 & 0 \\<br /> 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 1 & -4 & 1 & 0 & 0 & 0 \\<br /> 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 1 & -4 & 1 & 0 & 0 \\<br /> 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 1 & -4 & 1 & 0 \\<br /> 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 1 & -4 & 1 \\<br /> 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 1 & -4<br /> \end{array}\right][/tex]

The code for that is
\left[\begin{array}{cccccccccccccc}
1 & 0 & 0 & 0 & 0 & 0 & 0 & -4 & 1 & 0 & 0 & 0 & 0 & 0 \\
0 & 1 & 0 & 0 & 0 & 0 & 0 & 1 & -4 & 1 & 0 & 0 & 0 & 0 \\
0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 1 & -4 & 1 & 0 & 0 & 0 \\
0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 1 & -4 & 1 & 0 & 0 \\
0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 1 & -4 & 1 & 0 \\
0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 1 & -4 & 1 \\
0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 1 & -4
\end{array}\right]

Notice that, using \begin{array}, you need to put in the braces (\left[ and \right]) yourself (so you could use ( ), { }, etc.). The {cccccccccccccc} (14 c's) tells LaTex there are 14 columns.
 
Last edited by a moderator:
Thanks, that worked great.

Ryan
 
(I believe) There is a default for the maximum number of columns in the matrix environments, and that it is possible to change it in your document.

I don't have the pertinent information at my fingertips now; perhaps a search of tug.org
or some other site would be fruitful.
Edit: spoke too soon: from AMS math documentation, footnote on page 10.

More precisely: The maximum number of columns in a matrix is determined by the
counter MaxMatrixCols (normal value = 10), which you can change if necessary using LATEX’s
\setcounter or \addtocounter commands.
 
Thanks statdad.

Is there any advantage of using \begin{bmatrix} over \left[\begin{array}?

Ryan
 
ryan88 said:
Thanks statdad.

Is there any advantage of using \begin{bmatrix} over \left[\begin{array}?

Ryan

That I can't say, as I use the "bmatrix" environment exclusively. As some other posters have shown, it is possible to control column alignment in arrays; I don't know of a similar feature with the matrix environments.
 
Ok thanks
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 1 ·
Replies
1
Views
2K
Replies
7
Views
2K
Replies
2
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 8 ·
Replies
8
Views
4K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 21 ·
Replies
21
Views
2K