1

I have a problem with jumping to figure (not to the figure's caption) that has caption that includes inparaenum.

Minimal not working example:

\documentclass{article}
\usepackage{blindtext}
\usepackage{paralist}
\usepackage{graphicx}
\usepackage{hyperref}
\usepackage{caption} % see: https://tex.stackexchange.com/a/27102/44382

\begin{document}

Fig.~\ref{fig:test} is beatiful!

\blindtext[4]

\begin{figure}
    \centering
    \includegraphics[width=0.5\textwidth]{test}
    \caption[]{Linux distros: \begin{inparaenum}\item Ubuntu cat, \item Linux tux, \item Android \end{inparaenum}}
    \label{fig:test}
\end{figure}

\blindtext[4]

\end{document}

(To compile the above example you need some image called test.* – for example test.jpg.)

If you compile it, you'll see that jump to label doesn't work correctly unless you remove this inparaenum list:

\begin{inparaenum}\item Ubuntu cat, \item Linux tux, \item Android \end{inparaenum}

How can I solve this problem?

  • 2
    Works for me out of the box, the link leads to the correct image caption position By the way, you can use \usepackage[demo]{graphicx}, this way, nobody needs the test file –  Jun 05 '17 at 16:52
  • Sorry, I didn't precise my problem. I don't want to jump to the image's caption, but to the image itself (see similar problem). +1 for \usepackage[demo]{graphicx}. – patryk.beza Jun 05 '17 at 17:14
  • 1
    The problem is that \item does \refstepcounter (for possible reference to the items). – egreg Jun 06 '17 at 07:09

1 Answers1

1

The problem is that every \item command does \refstepcounter, which sets an anchor. This anchor will supersede the one related to the image.

If you don't plan to make cross references to these items, say that \refstepcounter should just do \stepcounter. If you need cross references, you're doomed.

\documentclass{article}

\usepackage{blindtext}

\usepackage{paralist}
\usepackage{graphicx}
\usepackage{caption} % see: https://tex.stackexchange.com/a/27102/44382
\usepackage{hyperref}

\begin{document}

Fig.~\ref{fig:test} is beatiful!

\blindtext[4]

\begin{figure}
\centering

\includegraphics[width=0.5\textwidth]{example-image}
\caption[Linux distros]{%
  Linux distros:
  \begin{inparaenum}
  \let\refstepcounter\stepcounter
  \item Ubuntu cat,
  \item Linux tux,
  \item Android
  \end{inparaenum}%
  \label{fig:test}%
}
\end{figure}

\blindtext[4]

\end{document}

Load caption before hyperref.

egreg
  • 1,121,712