# Hypcap not working with custom figure environment

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[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.

-

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}
-
I'm just figuring this stuff out but what exactly is the difference between [h] and [H]? Thanks! –  s0rce Feb 27 '12 at 5:39
@s0rce: You should read Frank Mittelbach's answer the following post: How to influence the position of float environments like figure and table in LaTeX? –  Werner Feb 27 '12 at 6:19

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{...}"

\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[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}
-