Math & ScienceMatrix numbering

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Post Reply
bazman
Posts: 78
Joined: Mon Jan 26, 2009 3:24 am

Matrix numbering

Post by bazman »

Hi there,

Last question for this evening:

I would like the matrix in the following to be given a number consistent with the other numebrs I am giving to my equations.

Code: Select all


\documentclass{article} % Your input file must contain these two lines
\usepackage{natbib}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{bm}
\usepackage{grffile}
\usepackage{graphicx}
\usepackage[%
  font=small,
  labelfont=bf,
  figurewithin=section,
  tablewithin=section,
  tableposition=top
]{caption}
\numberwithin{equation}{section}
\begin{document} % plus the \end{document} command at the end
\parskip = 1pc %change spacing between paragraphs
\parindent = 0pc %change paragraph indentation

\begin{equation}
\[ \left[ \begin{array}{lllll}
1 & a_1 & a_1a_2 & a_1a_2a_3 & a_1a_2a_3a_4 \\
a_1 & 1 & a_2 & a_2a_3 & a_2a_3a_4  \\
a_1a_2 & a_2 & 1 & a_3 & a_3a_4 \\
a_1a_2a_3 & a_2a_3 & a_3 & 1 & a_4 \\
a_1a_2a_3a_4 & a_2a_3a_4 & a_3a_4 & a_4 & 1 \end{array} \right]\]
\end{equation} 

\end{document}

Recommended reading 2024:

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

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

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

Matrix numbering

Post by localghost »

Why do you use this construction?

Code: Select all

\begin{equation}
  \[
    % your math expression
  \]
\end{equation}
You should get several errors.


Best regards
Thorsten
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Matrix numbering

Post by gmedina »

Hi,

instead of the array environment, you can use the bmatrix or pmatrix environments:

Code: Select all

\begin{equation}
  \begin{bmatrix}
    1 & a_1 & a_1a_2 & a_1a_2a_3 & a_1a_2a_3a_4 \\
    a_1 & 1 & a_2 & a_2a_3 & a_2a_3a_4  \\
    a_1a_2 & a_2 & 1 & a_3 & a_3a_4 \\
    a_1a_2a_3 & a_2a_3 & a_3 & 1 & a_4 \\
    a_1a_2a_3a_4 & a_2a_3a_4 & a_3a_4 & a_4 & 1 
  \end{bmatrix}
\end{equation}
1,1,2,3,5,8,13,21,34,55,89,144,233,...
bazman
Posts: 78
Joined: Mon Jan 26, 2009 3:24 am

Re: Matrix numbering

Post by bazman »

ah that's great!

Is it possible to make it left justified?
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Matrix numbering

Post by gmedina »

Of course:

Code: Select all

\begin{flalign}
  \begin{bmatrix}
    1 & a_1 & a_1a_2 & a_1a_2a_3 & a_1a_2a_3a_4 \\
    a_1 & 1 & a_2 & a_2a_3 & a_2a_3a_4  \\
    a_1a_2 & a_2 & 1 & a_3 & a_3a_4 \\
    a_1a_2a_3 & a_2a_3 & a_3 & 1 & a_4 \\
    a_1a_2a_3a_4 & a_2a_3a_4 & a_3a_4 & a_4 & 1
  \end{bmatrix} &&
\end{flalign}
1,1,2,3,5,8,13,21,34,55,89,144,233,...
bazman
Posts: 78
Joined: Mon Jan 26, 2009 3:24 am

Re: Matrix numbering

Post by bazman »

sorry I did not mean that the matrix should be left aligned but rather the elements inthe matrix
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Matrix numbering

Post by gmedina »

That's also possible. Two alternatives:

1) Using the array environment:

Code: Select all

\begin{equation}
  \left[% 
  \begin{array}{lllll}
    1 & a_1 & a_1a_2 & a_1a_2a_3 & a_1a_2a_3a_4 \\
    a_1 & 1 & a_2 & a_2a_3 & a_2a_3a_4  \\
    a_1a_2 & a_2 & 1 & a_3 & a_3a_4 \\
    a_1a_2a_3 & a_2a_3 & a_3 & 1 & a_4 \\
    a_1a_2a_3a_4 & a_2a_3a_4 & a_3a_4 & a_4 & 1 
  \end{array} 
  \right]
\end{equation} 
2) Using the bmatrix environment:

Code: Select all

\documentclass{article}
\usepackage{amsmath}

\makeatletter
  \def\env@matrix{\hskip -\arraycolsep
  \let\@ifnextchar\new@ifnextchar
  \array{*\c@MaxMatrixCols l}}
\makeatother

\begin{document}

\begin{equation}
  \begin{bmatrix}
    1 & a_1 & a_1a_2 & a_1a_2a_3 & a_1a_2a_3a_4 \\
    a_1 & 1 & a_2 & a_2a_3 & a_2a_3a_4  \\
    a_1a_2 & a_2 & 1 & a_3 & a_3a_4 \\
    a_1a_2a_3 & a_2a_3 & a_3 & 1 & a_4 \\
    a_1a_2a_3a_4 & a_2a_3a_4 & a_3a_4 & a_4 & 1
  \end{bmatrix}
\end{equation}

\end{document}
1,1,2,3,5,8,13,21,34,55,89,144,233,...
bazman
Posts: 78
Joined: Mon Jan 26, 2009 3:24 am

Re: Matrix numbering

Post by bazman »

Prefect thank you!
User avatar
Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

Matrix numbering

Post by Stefan Kottwitz »

Hi bazman,
bazman wrote:I did not mean that the matrix should be left aligned but rather the elements in the matrix
The solution of gmedina will effect all matrix environments like pmatrix, vmatrix, bmatrix etc. If you want to see a solution for matrices behaving like default but being more flexible have a look at an extension to amsmath matrix environments.

Stefan
LaTeX.org admin
Post Reply