The MWE works for me. Are you sure you compiled enough times? It takes at least two times for the changes in the labels to come trough. Also your MWE won't do anything good, since there is nothing to reference to (see @lockstep's answer).
–
romeovsFeb 5 '12 at 19:55

2 Answers
2

In its minimal or default form, \labels only store the counter and the page that it's on, the former retrievable via \ref and the latter retrievable via \pageref. TeX \label-\ref systems is used to mark the last referencable counter and store it in the \label. If there is no counter that was last referenced (as in your case), there will be no appropriate \ref, hence your ?? as output.

As a brief introduction to how one can use counter referencing, here is a way to achieve your result. First you define a counter using

\newcounter{mycount}

Then, whenever you want to store the counter for referencing, you perform

\refstepcounter{mycount}

This does two things: increases the counter by 1 (or "step" it), and adds a "referencing" capability or mark. Now, if you use \label it will store the value of mycount as well as the page that mycount was last \refstep-ped. Here's a minimal example of how that could work in your instance:

Now, this doesn't mean that you always have to create your own counter if you want to refernece something via \label-\ref. Instead, there are other counters that is \refstep-ped like section whenever you perform \section. Using the example above, if you had just placed \label{test} after the \section and subsequently used \ref{test}, you retrieve the section number 1 in the text.

Finally, you can also modify the way the counter is displayed in the text. For example, if you're interested in (lower case) Roman numerals for your counter, you could add

\renewcommand{\themycount}{\roman{mycount}}

after defining the counter mycount.

You need to compile twice for the references to be accurate, since information is first stored in an .aux file and retrieved upon the second compile.

FWIW: I had a similar problem and this answer is a bit over the top for me. Basically, I wanted to count citations used in a table, so I did basically: \refstepcounter{usedcitations}\label{usedcitationslabel} on every table entry and then anywhere in the document: \getrefnumber{usedcitationslabel}. Hope this helps someone.
–
Frederick NordFeb 10 '13 at 21:21