3

I use the caption package in my document to control the appearance of captions on figures and tables (small text, with bold labels):

\usepackage[font=small, labelfont=bf]{caption}

I use hyperref to make \listoffigures generate hyperlinks in the PDF. Captions are above their respective tables and figures in my document, and the hyperlinks correctly navigate such that the caption and figure are both visible on the screen.

This combination worked fine until I introduced floatrow to apply uniform formatting to the contents of figures and tables (small text, centered within margins, with caption still at the top):

\usepackage[font=small, margins=centering, style=plaintop]{floatrow}

With that addition, the hyperlinks navigate such that the caption is off the top of the screen. I've read about this problem before, but everything I've read (example 1, example 2) advises either to use caption after hyperref, or to use the hypcap package. I'm already doing the former, and the latter had no effect. On the other hand, other instances of this issue all seem to be when the caption is below the image, and the image is off the screen, not the caption.

If I remove either floatrow or caption, the links go to the right places, but then of course I lose the corresponding format changes that each package provides. How can I get all the formatting I want, and still have links go to the right places?

\documentclass{report}
\usepackage{hyperref}
\usepackage[font=small, labelfont=bf]{caption}
\usepackage[font=small, margins=centering, style=plaintop]{floatrow}

\usepackage{mwe, lipsum}

\begin{document}

\listoffigures

\clearpage

\lipsum[1]
\begin{figure}[h]
  % Links should navigate here.
  \caption{This is a figure}
  \label{figure1}
  % Links should not navigate here.
  \includegraphics{example-image}
\end{figure}
\lipsum[1]

\end{document}
  • Unlike the OP's self-answer, it's a bit unreasonable for me to remove floatrow - so if anybody can come with another solution to this problem that'd be sweet! – Bilal Akil Jun 29 '15 at 9:19
  • I've opened a similar question to try and bring this back alive: tex.stackexchange.com/questions/252773/… – Bilal Akil Jun 29 '15 at 9:44
0

I couldn't get caption and floatrow to work together, so I side-stepped the conflict by removing the latter package and implementing the requirements manually:

  • Float contents should be centered, so take some advice on how to automatically center an image and modify \@floatboxreset in the document preamble:

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

    Or, a little more concisely using etoolbox:

    \gappto\@floatboxreset{\centering}
    
  • Text in floats should be small; we can make that happen at the beginnings of the particular environments in use within the document. Again, using etoolbox:

    \BeforeBeginEnvironment{tabular}{\small}
    \BeforeBeginEnvironment{longtable}{\small}
    \BeforeBeginEnvironment{tikzpicture}{
        \tikzset{
            node font=\small,
        }
    }
    

    There is a related question about changing the font size of figure legends in which answers involve solutions similar to the centering change described earlier, where we redefine or patch \@floatboxreset, but they didn't seem to work for me. My solution has the possible side effect of changing the font size of other document components that happen to use tabular environments (the author section of \maketitle, for example), but in my case, I was lucky enough to avoid any issues.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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