GeneralNumbering matrices

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
msgj
Posts: 9
Joined: Tue Nov 20, 2007 3:12 pm

Numbering matrices

Post by msgj »

Can anyone tell me how I might number a matrix, line by line? I would like the numbers outside of the matrix delimiters, e.g. something like this:

| x x x |
| x x x | (2)
| x x x | (3)

If I use the equation environment with an array, then I will just get one number for the whole matrix. If I use an environment like align, there seems to be no way to get the matrix delimiters.

I have tried doing it manually with some code like this:

Code: Select all

\addtocounter{equation}{1}\newcounter{eqn}
\[C(\Gamma)=\left[\begin{array}{3}x_1&x_2&x_3\\
y_1&y_2&y_3\\
z_1&z_2&z_3
\end{array}\right]
\begin{array}{l}\\
(\theequation)\setcounter{eqn}{\theequation}\addtocounter{equation}{1}\\
(\theequation)\\
\end{array}\]
in which I put the numbers in a second array and increment the counter manually. (The numbers for the second and third lines are stored in the counters eqn and \theequation respectively.)

However, this is not a satisfactory solution, and does not work when I introduce chapters because then the line numbers become of the form 2.13 which are not incremented so easily.

If there is an environment which will do this for me, please let me know!

Thanks.

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

gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Numbering matrices

Post by gmedina »

I don't know if some package directly offers you the solution to your problem. However, your approach seems more or less right. You can achieve the numbering in a simpler way using something like this

Code: Select all

\documentclass{article}
\usepackage{amsmath,array}

%***the new counter*******************************
\newcounter{mymatrow}
\stepcounter{mymatrow}

\begin{document}
\[
\left[
\begin{array}{cc}
  0 & 1\\
  0 & 1\\
  0 & 1
\end{array}
\right]
\hspace{5pt}
\begin{array}{l}\\
(\themymatrow)\stepcounter{mymatrow}\\
(\themymatrow)\\
\end{array}
\]

\end{document}
1,1,2,3,5,8,13,21,34,55,89,144,233,...
msgj
Posts: 9
Joined: Tue Nov 20, 2007 3:12 pm

Numbering matrices

Post by msgj »

Thanks for the reply. But then ...

a) how would I refer to the first of the two labels? (i.e. how do i subtract 1 from mymatrow in the \ref command?)

b) these numbers would not follow other numbers in the document, and would not be in the style chapter.number, would they?
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Numbering matrices

Post by gmedina »

Then you can try something like this:

Code: Select all

\documentclass{book}
\usepackage{amsmath,array}

\begin{document}

\chapter{First chapter}

\begin{center}
  \begin{minipage}{.3\linewidth}
    \begin{equation*}
    \renewcommand{\arraystretch}{1.25}
    \left[
    \begin{array}{cc}
      0 & 1\\
      0 & 1\\
      0 & 1
    \end{array}
    \right]
    \end{equation*}
  \end{minipage}\hspace{-2.5cm}
  \begin{minipage}{.2\linewidth}
  \vspace*{3pt}
    \begin{align}
    \ \label{mat:row1}\\
    \ \label{mat:row2}
    \end{align}
  \end{minipage}
\end{center}
As the rows \ref{mat:row1} and \ref{mat:row2} show,...

\end{document}
It is not an optimal solution, but at least you can cross-reference the rows of the matrix using the standard commands and you won't need to worry about new counters.
1,1,2,3,5,8,13,21,34,55,89,144,233,...
User avatar
Juanjo
Posts: 657
Joined: Sat Jan 27, 2007 12:46 am

Re: Numbering matrices

Post by Juanjo »

The above approaches can fail if the heights of the matrix rows are a bit different. For example, replace 1 by \dfrac{1}{2}: alignment between a row and the corresponding number is lost. So you should have to use \phantom and like. In addition, some adjustment is required to vertically align row labels with the remaining equation labels in the page.

Instead of searching a LaTeX solution for the problem, I wonder if it would be preferable to write things in a different way. From a mathematical standpoint, it is strange to number rows of a matrix instead of the whole equation. If I were a reader of the document, I would prefer to see something like "the second row of the matrix in (1.2)", instead of "the row (1.2)", which sounds rare.
msgj
Posts: 9
Joined: Tue Nov 20, 2007 3:12 pm

Re: Numbering matrices

Post by msgj »

Thanks for both of your suggestions. I will let you know how I get on.

Happily there are no fractions in the matrices, so hopefully vertical alignment won't be a problem. I take your point about referring to the lines in a matrix, but I still prefer to do it this way if I can! Actually they are not matrices but presentations of groups (I didn't want to make the question unnecessarily complicated.) Thus I don't want to refer to "the second line of the relations in the presentation above ..." but simply to "relations 1.2".
msgj
Posts: 9
Joined: Tue Nov 20, 2007 3:12 pm

Re: Numbering matrices

Post by msgj »

I attach a page from my thesis so you can see what I'm talking about. I'm using square brackets for the presentations rather than the traditional angled ones, to save space.
Attachments
example.pdf
(64.85 KiB) Downloaded 277 times
Post Reply