TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I picked up a template to write exams a while ago only. Each problem is written between \begin{problem} and \end{problem}. In the preamble I have

%    (this page style suppresses page numbers.)

%Adjust the margins:

%puts in a horizontal  rule the width of the text with space
%before and after.

%A new environment for a test problem.


I replaced \stepcounter{problem} with \refstepcounter{problem}. I do the following when I try to cross-reference:

Answer this question
Refer to problem~\ref{labelname}. Now answer this question.

However, when I compile the .tex file, the PDF file shows "Refer to problem ??. Now answer this question."

How could I fix this? I appreciate the help.

share|improve this question

After the first run I get the behavior you describe:

enter image description here

But when run again (without deleting the .aux files that are produced in the first run), you obtain the desired results:

enter image description here

Since it is possible to reference a figure before it is placed, two runs are required. The first determines the figure numbers placing a temporary ?? as a placeholder for the reference, and the second resolves the references.

share|improve this answer
Awesome! It does work. Thanks a lot. – user87317 Nov 30 '12 at 19:36

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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