I have the following code:




A nice paper has the following things:

  data RCPoint = RCPoint {
    _rcp_si :: Integer
  \caption{The RCPOINT Listing}

  x^2 - 2 x

I like my equation in \ref{eq:eqn1}.

I also like my code in Listing \ref{ch1}.


which compiles normally, to produces::

PDF - Notice no listing number

The reference to the listing in the final line is missing. I get a warning for the final line of output:


Package hyperref Warning: Suppressing empty link on input line 55.

[1] (./nice-org-paper.aux) )
Output written on nice-org-paper.pdf (1 page).
Transcript written on nice-org-paper.log.

How do I get the reference to work?

  • You forget your question, in my point of view – user31729 Mar 9 '14 at 9:12
  • I see who I could have clarified that. – stevejb Mar 9 '14 at 20:09
  • 1
    I see now why it is marked as duplicate, but I realize that I did not even know the question to ask. I did not know about the ordering issue. – stevejb Mar 9 '14 at 20:10
  • @stevejb: You did have the question in the post, but it was only in the alt text of the image: ![The question was in these square brackets](image link). This shows up in screen-reading software, or if the image can’t be loaded, but some (most?) people won’t see that. You can find out more on the Markdown help page. – alexwlchan Mar 9 '14 at 20:23

The problem is that your \label occurs before your \caption. You should always put your \caption before \label.

The number for the listing gets assigned by \caption, so you should swap the two lines

\caption{The RCPOINT Listing}


\caption{The RCPOINT Listing}

and then your code should produce what you expect.

You can find out more about this problem in egreg’s answer to Why does an environment's label have to appear after the caption?

  • What's the design choice behind \caption always coming before \label? – rafaelvalle Feb 24 '17 at 6:22

Not the answer you're looking for? Browse other questions tagged or ask your own question.