enter image description here

I cannot reference correctly whenever I am in the subsection-level. The first reference to "equation of motion, 4.1" is fine, but the next reference, i.e. "Rearranging (4.1.3)" is supposed to be "Rearranging (4.11)".

Here's a code snippet:

\end{equation} \label{eq:modal11} 
Rearranging \eqref{eq:modal11} yields:
  • Welcome to TeX.SE. Please post the code that gives rise to the problem you wish to fix. My hunch is that the problem is related to either missing or mis-placed \label instructions. The only way to verify (or disprove...) such a hunch is to see the actual LaTeX code.
    – Mico
    Jun 2, 2018 at 17:44
  • begin{equation} (Ms^2+Cs+K)X(s)=F(s) \end{equation} \label{eq:modal11} Rearranging \eqref{eq:modal11} yields:
    – Viggo
    Jun 2, 2018 at 17:46
  • 7
    so you have \label outside the equation so it is labelling the current section Jun 2, 2018 at 17:47
  • I just realized that myself. Cant believe I just spent about an hour troubleshooting and almost gave up
    – Viggo
    Jun 2, 2018 at 17:48
  • I've posted an answer, both to (re)state the main recommendation and to provide an explanation of why it matters where a \label directive is placed.
    – Mico
    Jun 3, 2018 at 6:48

1 Answer 1


(posting this answer mainly so that it can be checked off as having been answered)

To start off, here's a recreation of the relevant part of your screenshot, with the cross-reference pointing to the subsection header instead of to the preceding equation:

enter image description here

\usepackage{amsmath}    % for "\eqref" macro
%%% Just to recreate the OP's setup:
\setcounter{chapter}{4}    \refstepcounter{section}
\setcounter{subsection}{2} \setcounter{equation}{10}
\subsection{Here we go} % create a dummy subsection-level header

Assuming the initial conditions to be zero yields:
\end{equation}  \label{eq:modal11}%% "\label" outside equation env.
Rearranging \eqref{eq:modal11} yields:

As David Carlisle has observed in a comment, the problem arises because you placed the equation-specific \label instruction outside the equation environment. Sure enough, moving the \label instruction inside the equation environment -- say, immediately after \begin{equation} -- and recompiling twice yields the desired outcome as far as the cross-reference is concerned:

enter image description here

You may ask, "why is it necessary to place the equation-related \label instruction inside the equation environment?" To answer this question, it's necessary to take a closer look at how LaTeX's \label-\ref mechanism works.

  • The \label-\ref mechanism works by \label latching on to an internal, low-level LaTeX macro called \@currentlabel. LaTeX associates this macro with the counter variable that was most recently incremented via a \refstepcounter instruction. As its name suggests, \refstepcounter not only increments a counter variable but does so in a way that "wakes up" the \@currentlabel macro if a \label instruction is issued.

  • Importantly, not all counter-incrementing actions are created equal in terms of their global reach within the document. Some counters -- mainly those associated with \chapter, \section, \subsection etc sectioning commands -- are visible globally, in the sense that \@currentlabel remains associated with those counters at the global, i.e., document-wide, level until \@currentlabel is modified once more (most likely via a \label instruction).

  • In contrast, other counter variables -- notably, those associated with equation, theorem, figure, and table environments -- are incremented inside their respective environments. (Aside: In figure and table environments, the counter variable is incremented by the \caption instruction. That's why it's necessary to place the \label instruction after the \caption instruction for these two environments.) One might regard these counters as being "local" to their respective environments. If a \label instruction is encountered inside these environments, the \@currentlabel macro will latch on to the intended counter, and all is well as far as the \label-\ref mechanism is concerned.

  • In contrast, if the \label instruction isn't run until after the LaTeX environment has ended, LaTeX no longer "knows" which counter, if any, was incremented most recently inside that environment. Therefore, when the \label instruction is run, \@currentlabel gets associated with the most-recently labelled "global" counter variable; in the case of your sample document, that happens to be the subsection counter. (Aside: If, in the example code shown above, one were to delete the \subsection instruction and recompile twice, one would find that the cross-reference now points to the section-level counter ("4.1").)

What's the moral of this story? If one employs LaTeX environments (e.g., equation and theorem) which increment counter variables and wishes to cross-reference them, one must place the \label instruction inside those environments.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .