Equation label is wrong

I am currently trying to cite an equation array, but it is citing me the next equation, weirdly (see figure). Can anyone help me?

I am using the following code:

Considering a logarithmic transformation, the P-wave signal $p[n]$ and its Gaussian model $\hat{p}[n]$ were related as:
\begin{eqnarray}
ln(p[n])&=&ln(\hat{p}[n])
\\\nonumber &=&ln(A) - \bigg(\frac{n-C}{W}\bigg)^2 \label{eq:log_gauss}
\end{eqnarray}
Defining the variables $b=ln(p[n])$, $a_2=-1/W^2$, $a_1=2C/W^2$, and $a_0=ln(A)-(C/W)^2$, Equation \ref{eq:log_gauss} can be written as a second-order polynomial:
\begin{eqnarray}
b&=&-\frac{1}{W^2}n^2+\frac{2C}{W^2}n+ln(A)-\bigg(\frac{C}{W}\bigg)^2
\\\nonumber &=&a_2n^2+a_1n+a_0
\end{eqnarray}
Considering discrete values of $n$, coefficients $a_2$, $a_1$, and $a_0$ can be obtained by solving the following system of linear equation:


• Please move the \nonumber before \\ . And use \ln instead of ln. – marmot Sep 27 '18 at 15:34
• It worked! Why tho? Btw, post this as answer, so that I can mark it as correct – Take2 Sep 27 '18 at 15:41
• The reason is that you tell latex not to put a number at a line of an equation that you want to label. So, in a way, this label is "lost" and cannot be referenced (correctly). (Personally I prefer to put the number at the last line of the equation, and that's why I suggested to move \nonumber up. I also would refrain from using : but these are of course just opinions.) – marmot Sep 27 '18 at 15:45
• Hehe, you just hit one of my examples in the tugboat article I wrote about why you should ever ever use eqnarray, it steps up the equation counter at the start of a row, and steps it down at the end if \nonumber is used. But in between \label can easily pickup equation data, see tugboat 33-1 2012, tug.org/TUGboat/Contents/contents33-1.html – daleif Sep 27 '18 at 16:25
• @daleif I am not going to write an answer, so please feel free to do so. (It would be great if you could add to this answer how to increase the space around the equality signs a bit. I know that the spacing in eqnarray has often been dubbed "excessive" but perhaps not by those who really have to read papers and try to access the information contained in the equations very efficiently. I'd love to know a trick which just adds some space around = signs in display mode, not as much as in eqnarray.) – marmot Sep 27 '18 at 16:48

The placement of \nonumber is wrong.

However, you should never use eqnarray. Besides producing wrong space around the equals signs, it doesn't cooperate with hyperref.

I suggest using split, since you're referring to the whole equations and not just to one line.

\documentclass{article}
\usepackage{amsmath}

\begin{document}

Considering a logarithmic transformation, the $P$\nobreakdash-wave signal
$p[n]$ and its Gaussian model $\hat{p}[n]$ were related as
$$\label{eq:log_gauss} \begin{split} \ln(p[n]) &=\ln(\hat{p}[n]) \\ &=\ln(A) - \biggl(\frac{n-C}{W}\biggr)^{\!2} \end{split}$$
Defining the variables $b=\ln(p[n])$, $a_2=-1/W^2$, $a_1=2C/W^2$,
and $a_0=\ln(A)-(C/W)^2$, Equation \ref{eq:log_gauss} can be written as
a second-order polynomial
$$\begin{split} b&= -\frac{1}{W^2}n^2+\frac{2C}{W^2}n+\ln(A)-\biggl(\frac{C}{W}\biggr)^{\!2} \\ &=a_2n^2+a_1n+a_0 \end{split}$$
Considering discrete values of $n$, coefficients $a_2$, $a_1$, and $a_0$
can be obtained by solving the following system of linear equations

\end{document}


Note \ln instead of ln. Also \biggl( and \biggr) should be used, not the unadorned \bigg in either case.

As @marmot correctly said, I do not want to take his credit, you have to shift the \nonumber command before the \\ and use the \ln command for the logarithm instead of just writing ln.

I write this answer so that someone, like me, who encounters the same (or a similar one) problem knows that it has been solved.