5

I'm trying to use caption with hypcap=true so that cross-reference hyperlinks will go to the figure instead of the figure caption. However, I'm using a multicol environment with a custom figure environment so that the floats place well in the two-column document.

Here is a MWE:

\documentclass[10pt, letterpaper]{article} 
\usepackage{multicol}
\usepackage[small,bf,hypcap=true]{caption}
\usepackage[demo]{graphicx}
\newenvironment{Figure}
  {\par\medskip\noindent\minipage{\linewidth}}
  {\endminipage\par\medskip}
\usepackage[unicode, bookmarks, colorlinks, breaklinks]{hyperref} 
\usepackage[all]{hypcap} %I don't know if this line is needed

\begin{document}
\begin{multicols}{2}[\section{section1}]
Figure~\ref{fig:fig1}
\begin{Figure}
\centering
\includegraphics[width=\textwidth]{apple.jpg}
\captionof{figure}{caption}
\label{fig:fig1}
\end{Figure}
\end{multicols}
\end{document}

I'm using XeLaTeX but I don't think that changes anything.

s0rce
  • 1,180

2 Answers2

5

There are two reasons why your hyperlink is not working correctly:

  1. When using the hypcap package the caption package will not place hyperlink anchors anymore, since the hypcap package is taking responsibility for this task. So don't use it here, otherwise no hyperlink anchor will be placed at all, at least not by the caption package. See section 6.6 "hypcap" in the caption package manual. (As an alternative one could use \capstart here, see hypcap package manual for details.)

  2. When using \captionof the caption package does only know where the caption is placed, but does not know where the figure actually starts, i.e. where it should place the hyperlink anchor. So use \captionsetup{type=figure} for this task and avoid using \captionof. See section 6.5 "hyperref" in the caption package manual, especially the paragraph "\captionof{...}{...} vs. \captionsetup{type=...}+\caption{...}"

Your example document, modified:

\documentclass[10pt, letterpaper]{article} 
\usepackage{multicol}
\usepackage[small,bf,hypcap=true]{caption}
\usepackage[demo]{graphicx}
\newenvironment{Figure}
  {\par\medskip\noindent\minipage{\linewidth}%
   \captionsetup{type=figure}}% \captionsetup{type=figure} added
  {\endminipage\par\medskip}
\usepackage[unicode, bookmarks, colorlinks, breaklinks]{hyperref} 
%\usepackage[all]{hypcap} % No, this line is not needed

\begin{document}
\begin{multicols}{2}[\section{section1}]
Figure~\ref{fig:fig1}
\begin{Figure}
\centering
\includegraphics[width=\textwidth]{apple.jpg}
\caption{caption} % \captionof replaced by \caption
\label{fig:fig1}
\end{Figure}
\end{multicols}
\end{document}
3

You should use float package to use H placement specifier:

\documentclass{article} 
\usepackage{multicol}
\usepackage[small,bf,hypcap=true]{caption}
\usepackage[demo]{graphicx}
\usepackage{float}
\usepackage[unicode]{hyperref}

\begin{document}
\begin{multicols}{2}[\section{section1}]
Figure~\ref{fig:fig1}
\begin{figure}[H]
\centering
\includegraphics[width=\linewidth]{apple.jpg}
\caption{caption}
\label{fig:fig1}
\end{figure}
\end{multicols}
\end{document}
Leo Liu
  • 77,365