Page LayoutNumbering of gathered Equations

Information and discussion about page layout specific issues (e.g. header and footer lines, page formats, page numbers).
Post Reply
Magnolis
Posts: 13
Joined: Wed Apr 04, 2012 1:45 pm

Numbering of gathered Equations

Post by Magnolis »

Hi, until now I was using the eqnarray command, but the wrong spacing forced me to try something else, such as the gather command: I prefer this one over any other alignment command (for spacing reasons), but now there are some problems with equations' numbers:
  1. no number is shown next to the equation;
  2. there is only one label for all the lines (despite I'm not using *)
  3. references to the numbers show something like (3.4), which is the number of the chapter, instead of (13), for example.
Here is a simple code:

Code: Select all

\begin{gather}
a=b  \label{one} \\ \label{two}
c=d \\ \label{three}
\end{gather}
($\ref{one}$) ($\ref{two}$) ($\ref{three}$)
The three references displayed are (3.4)(3.4)(3.4). The amsmath package is correctly declared in preamble. 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

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

Numbering of gathered Equations

Post by localghost »

No problem here.

Code: Select all

% !TeX program = pdflatex
\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage{mathtools}   % loads »amsmath«

\begin{document}
  \begin{gather}
    a=b \label{one} \\
    c=d \label{two} \\
    e=f \label{three}
  \end{gather}
  \eqref{one} \eqref{two} \eqref{three}
\end{document}

Thorsten
Magnolis
Posts: 13
Joined: Wed Apr 04, 2012 1:45 pm

Re: Numbering of gathered Equations

Post by Magnolis »

Thanks, I copied your example into a new document and it worked fine, but unfortunately it gave me the same errors written above if inserted into the one I am working on: the reason is that, for some strange reason, at a certain point equations are labelled with a negative number using eqnarray while, if I use gather, it's the chapter number.
I know, I must replace every single eqnarray with gather into the document but there are tons of formulas and, when I tried to replace them all using the proper command, many equations where messed up, so I was planning to do it at last, with a lot of patience.

Now I am checking when the first negative number appears in the document (it's -11) but there is nothing wrong neither with that equation, nor with the previous. What do you think?
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Numbering of gathered Equations

Post by localghost »

Magnolis wrote:[…] for some strange reason, at a certain point equations are labelled with a negative number using eqnarray while, if I use gather, it's the chapter number. […]
So you've got a critical point in your source that you can isolate. Hence it should be no problem to prepare a proper minimal example.
Magnolis wrote:[…] I know, I must replace every single eqnarray with gather into the document but there are tons of formulas and, when I tried to replace them all using the proper command, many equations where messed up, so I was planning to do it at last, with a lot of patience. […]
It's better to replace {eqnarray} by the align environment.
Magnolis
Posts: 13
Joined: Wed Apr 04, 2012 1:45 pm

Numbering of gathered Equations

Post by Magnolis »

localghost wrote: So you've got a critical point in your source that you can isolate. Hence it should be no problem to prepare a proper minimal example.
It's not so easy: actually the document is quite long and I put a lot of \nonumber command, in order to hide numbers, so I don't know where the critical point is. I tried by counting equations backward, -11, -10, -9 etc. until I get to 0, but suddenly numbers became positive. I was expecting some kind of hint, such as "usually negative numbering appears because..." (also internet does not mention this problem) but, if you didn't, it means that it must be solved the hard way.
localghost wrote: It's better to replace {eqnarray} by the align environment.
I also tried this one but some formulas overlapped figures, because of "wrapfigure" command. "gather" is not my final choice, I will try again your suggestion.
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Numbering of gathered Equations

Post by localghost »

Magnolis wrote:[…] I tried by counting equations backward, -11, -10, -9 etc. until I get to 0, but suddenly numbers became positive. […]
And this is exactly your point where to start in the source.
Magnolis
Posts: 13
Joined: Wed Apr 04, 2012 1:45 pm

Re: Numbering of gathered Equations

Post by Magnolis »

The problem seems to be more complicated than expected: I have searched and found equation (0), by backward counting equations: this one has nothing wrong and, if I erase \nonumber both in this and in the previous one, they are labelled as (1) and (2), so numbering starts again from a new point.

At last I have tried something different, deleting all \nonumber commands: numbering seems to work properly, except for the fact that I don't want to see all those numbers.

My opinion is that there is no equation (0), but somehow the very first formulas I wrote work properly, so it may exists.
I must mention one strange thing: at a certain point, two equations have their numbers slightly back respect to the others (again, syntax is correct). Some lines above, is located the last equation whose number works properly.

If no more suggestions are given, as a final attempt I could substitute manually every single "eqnarray" with "gather" (or "align")... hard work, I am afraid to do it for nothing.
Magnolis
Posts: 13
Joined: Wed Apr 04, 2012 1:45 pm

Numbering of gathered Equations

Post by Magnolis »

The document is finally fixed! It took around 2-3 hours but now all the equations work properly. I will share my experience. My method was erasing "*" into "gather*", in order to show numbers, until I find the last working equation and the first not working one, then searching for what is wrong.
There were 2 problems:
  • 1. the main problem was a single \nonumber outside any equation environment: starting from that point, numbering stopped working: pdf didn't show it, so it was hidden;
    2. the secondary problem was where I inserted the \label{equation} command. If an equation takes more than 1 line, you have to write \label{equation} next to the numbered line, like this

    Code: Select all

    \begin{gather}
    a+b+c=1 \nonumber\\
    d+f+g=6 \label{equation}  %Right
    \end{gather}
    
    NOT like this

    Code: Select all

    \begin{gather} \label{equation} %Wrong
    a+b+c=1 \nonumber\\
    d+f+g=6
    \end{gather}
    
    otherwise the reference will be something like (2.6) (chapter's number) instead of (14), for example.
I think that the "eqnarray" environment does not have the second problem, but anyway I highly recommend to avoid it and choose "gather" (or "align") instead. That's it, thanks to localghost anyway.
Post Reply