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.

My document:

\documentclass[12pt,a4paper]{mwrep}
\usepackage{polski}
\usepackage[utf8]{inputenc}

\usepackage[hidelinks,unicode]{hyperref}

\usepackage[T1,OT4]{fontenc}
\usepackage{graphicx}
\usepackage{hypcap}

\let\origfigure\figure
\let\endorigfigure\endfigure

\makeatletter
\g@addto@macro\@floatboxreset\centering
\makeatother

\begin{document}

\tableofcontents
\listoffigures

\chapter{Bzdety}\label{rozdzial-bzdety}
W rozdziale \ref{rozdzial-bzdety} ze strony \pageref{rozdzial-bzdety}
znajduje się obrazek \ref{obraz-jesien} na stronie \pageref{obraz-jesien}.

The first paragraph.

\begin{figure}
    \includegraphics{a.jpg}
    \caption[Opcjonalny skrócony opis do spisu obrazków]{Opis}
    \label{obraz-jesien}
\end{figure}

The second paragraph.
\end{document}

hyerref makes nice hyperlinks to captions of images. I can for example create list of figures. That is nice. But every link is going to caption and image is above it so reader needs to scroll up to see it. How can I change something in preamble so clicking on such hyperrlink leads to the top of image? I don't want to change anything outside preamble unless necessary.

share|improve this question
    
hyperref should be loaded last but right before hypcap. It means no more \usepackage commands can exist after \usepackage[]{hyperref}\usepackage{hypcap}. –  xport Jul 17 '11 at 10:14
    
That's not precisely true: for example also bookmark should be loaded after hyperref (and it's advised to do this, since bookmark provides better bookmark management). –  egreg Jul 17 '11 at 10:20
    
@Ichibann: The second version of your MWE allowed me to find an answer. Note, however, that the draft option has to be added to the graphicx package to make your example compilable if one lacks the file a.jpg. –  lockstep Jul 17 '11 at 10:38
add comment

1 Answer

up vote 6 down vote accepted

Load hypcap with the all option: \usepackage[all]{hypcap}. See section 1.1 of the documentation for details.

EDIT: Here's a rather minimal working example (only the code for centering floats is retained):

\documentclass{mwrep}

\usepackage[draft]{graphicx}
\usepackage{hyperref}
\usepackage[all]{hypcap}

\makeatletter
\g@addto@macro\@floatboxreset\centering
\makeatother

\begin{document}

\listoffigures

\chapter{foo}

\begin{figure}[h]
  \includegraphics{a.jpg}
  \caption{Opis}
\end{figure}

\end{document} 
share|improve this answer
    
OK, thanks. Why I'm getting ! LaTeX Error: Option clash for package graphicx.See the LaTeX manual or LaTeX Companion for explanation.Type H <return> for immediate help.... \usepackage when trying to use [draft]? I'm sorry about MWE - I don't know exactly what should I leave and what can be ommitted :( –  Ichibann Jul 17 '11 at 10:44
1  
You mean in your "real" document? Possibly another package loads graphicx without options before you try to load it with the draft option. Try to move up \usepackage[draft]{graphics} in your preamble. –  lockstep Jul 17 '11 at 10:47
    
And you shouldn't be sorry about your MWE -- finding out what is relevant for the problem at hand often involves trial and error, and your second MWE version was much better than the first. –  lockstep Jul 17 '11 at 10:49
    
You were right:). I moved it up and it works :). Thanks! –  Ichibann Jul 17 '11 at 10:53
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.