1

A weird, possibly trivial, problem is happening.

After running pdflatex test with the following in the file test.tex

% -*- coding: utf-8 -*-
\documentclass[11pt]{article}
\begin{document}
\thispagestyle{empty}
We greet in Figure~\ref{myfig}.

\begin{figure}[h]
  \centering\large hello
  \label{myfig}
  \caption{greet}
\end{figure}

\end{document}

one time, I find in the file test.aux, as expected:

\relax 
\newlabel{myfig}{{}{1}}

and I duly get warned that:

LaTeX Warning: There were undefined references.

LaTeX Warning: Label(s) may have changed. Rerun to get cross-references right.

But after a second run of pdflatex test, the number 1 does not appear where it should

missing reference

and the warning no longer appears, suggesting all is well.

Where should I be looking?

(I've tried:

  • Deleting the aux file and recompiling.
  • Using xelatex and lualatex.

)

I'm using TeX Live 2015 on El Capitan.

Calaf
  • 1,471

1 Answers1

2

Well, your problem is independend from your used operating system and tex distribution.

It is important to write first \caption, then \label. Please have for example an look to this question or take a look to the LaTeX companion or other LaTeX documentations.

So with the follwing MWE

\documentclass[11pt]{article}
\begin{document}
\thispagestyle{empty}
We greet in Figure~\ref{myfig}.

\begin{figure}
  \centering\large hello
  \caption{greet}
  \label{myfig}
\end{figure}

\end{document}

you will get no errors or warnings after two compile runs or more. Please see that I deleted the option [h] for your figure environment. Please use this option only if it is really needed and btw only using [h] will cause an warning, you should then, only if needed, [ht] or simular.

Mensch
  • 65,388
  • I think of the caption as optional, and indeed in some styles, it is. But it still makes sense to increment the counter within \caption{}. If the caption is omitted, it's assumed that the figure's location will be rigidly monitored and that the reference to the figure will be informal. – Calaf May 03 '16 at 18:55
  • 1
    @Calaf: Without \caption (or \captionof{figure}) there's no increment of the figure counter (and nothing that displays the value of the figure counter, i.e \thefigure. A manual increment within caption is not recommended –  May 03 '16 at 21:39
  • @ChristianHupfer I didn't express myself well. I didn't mean that I would increment the counter myself, just that it gets incremented as a side effect of executing \caption{}. The style I'm thinking of (figures and text are interspersed, with no references or captions) is a variation on using package wrapfig. – Calaf May 04 '16 at 02:36