Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

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}
share|improve this answer
    
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
5  
@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
add comment

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}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.