0

I do have this short file

\documentclass%[colorlinks=true]
{memoir}
\usepackage[pdftex]{hyperref}
\begin{document}
%\chapter{first}
Here goes the figure.
\begin{figure}[!h]
\label{fig:MyFigure}
this is the figure itself
\caption{The figure caption}
\end{figure}

Next part of text.
Refer to Fig \ref{fig:MyFigure} on page \pageref{fig:MyFigure}.
\listoffigures
\end{document}

The result shows up like this:

Next part of text. Refer to Fig on page 1.

I.e. the Fig number is missing. When I uncomment [colorlinks=true], some very narrow rectangle is visible after Fig, so I guess somehow \ref{} generates nothing. At the same time, \pageref{} seems to work OK. Also, \listoffigures "sees" the figure. After uncommenting \chapter{first}, the compilation is OK. (The same effect also on ShareLaTeX, so it is not a TeX configuration problem.)

Also, I do have figure number "1.1", and in the reference I see "1". when having more than one figure, the figure sequence number is OK, but in the reference I see some increasing number, with 3-4 step size; at the same time the hyperref jump seems to take to the right place.

Do I miss something, or it is a bug?

katang
  • 1,429
  • 2
    Move \label{fig:MyFigure} after \caption{}. – Sigur Jan 03 '15 at 14:34
  • Thanks, it works. It is a kind of undocumented feature? – katang Jan 03 '15 at 14:45
  • 2
    Always use labels just before to close the environment. – Sigur Jan 03 '15 at 14:46
  • Till now, I guessed that ' \begin{figure}[h!btp]\label{fig:MyFigure}' is a correct configuration – katang Jan 03 '15 at 15:06
  • 2
    @user11708: Not, it's not an undocumented feature. A \label relies on a \refstepcounter{countername} to be done before. In your case, the \caption does the \refstepcounter{figure} for you and you have to put \label accordingly after \caption –  Jan 03 '15 at 15:20
  • Remember that you can have more than one caption I a figure float. So it would not make sense if it was the float that gave you the number to refer to. If I'm not mistaken some captioning extention packages cab even detect errors like this – daleif Jan 03 '15 at 15:34
  • @Christian Hupfer So, \caption{MyCaption \label{fig:MyFigure}} seems to be OK, for both above figure and below figure cases? – katang Jan 03 '15 at 15:35
  • @user11708: Not recommended! \caption{MyCaption}\label{fig:MyFigure}, i.e. outside –  Jan 03 '15 at 15:36
  • @Christian Hupfer I uses \label to refer to the figure. My captions are usually below the figure, so the hypertarget is also below the figure. Can I make somehow to jump to the top of the figure, rather than to the bottom? What is the relation between \label and \phantomsection? – katang Jan 03 '15 at 15:42
  • @user11708: See the hypcap package. – Werner Jan 03 '15 at 15:51
  • @Werner -- i didn't know about the hypcap package, and there's nothing in the linked duplicate that mentions it. maybe add a mention there. – barbara beeton Jan 03 '15 at 19:34

0 Answers0