# Subfig package and tufte class

I am using the subfig package in combination with the tufte latex class. Unfortunately I did not manage to make it work error free. As discussed in other forums (see here), the subfig package alters the caption size of all floats, which can be prevented by using the option caption=false when loading the package. However, this somehow confuses the hyperlinks in the document, such that figure and table references are linked to section headers instead of the figures and tables.

Here is an example of the problem I have

\documentclass{tufte-book}

%\usepackage[caption=false]{subfig}
\usepackage{subfig}

\begin{document}
\chapter{A}
\section{This section}
If [caption = false] is used, the hyperrefs go to the section heather above, instead of going to Figure~\ref{testfig} or to Table~\ref{testtab}. If it is not used, the hyperrefs work, but the figure captions are printed with a bigger fontsize than they usually do.

\vspace{10cm}

\begin{figure}
\caption{This is the test figure}\label{testfig}
\end{figure}

\begin{table}
\caption{This is the test table}\label{testtab}
\end{table}

\end{document}


I know this is a detail, but I am curious if there is a workaround. I have no clue on how to solve this issue on my own.

Thanks in advance for any help!

-
Since the subfig package is deprecated, you might try the newer subcaption package. –  SFAB Aug 1 '12 at 14:18
It took me a moment to figure out how to load the subcaption package together with the tufte-latex class (had to use the option \captionsetup{compatibility=false} in the preamble). Then the package can be loaded, but unfortunately the subcaption package also changes the font style in figures and tables, so its not help either... –  yellowcap Aug 3 '12 at 14:54

An easy fix for this is to issue a \phantomsection at the start of the float you have a reference to:

\begin{figure}
\phantomsection
% Other figure stuff
\caption{...}\label{..}
\end{figure}


or automate this procedure for all figures and tables using etoolbox:

\usepackage{etoolbox}% http://ctan.org/pkg/etoolbox
\AtBeginEnvironment{figure}{\phantomsection}
\AtBeginEnvironment{table}{\phantomsection}


The above "patch" ensures that a hyper anchor is placed at the top of the respective floats; something required by the \label-\ref system to accurately jump within the PDF.

-
This fix seems to work fine when I include the \phantomsection command by hand, but the automatic fix did not provide good results. thanks for both answers! –  yellowcap Aug 1 '12 at 16:30
@yellowcap: What in terms of the automated solution does not provide good results? The only reason it won't provide good results is if you insert a \label at an arbitrary position away from a counter increment. For example, you insert (say) \section{Something} and then insert a figure and then insert the section \label near the end of the section (after the figure). Typically, you would \label where the counter is incremented. Maybe you don't; just a guess. –  Werner Aug 1 '12 at 17:44
sorry I was not clear on that. I played around with the figures some more, and the problem appears when the location of the figures is set using something like \begin{figure}[t]. Then the link seems to go to the location of the figure would have without the [t] option. I use this option in most figures because tufte-latex usually places the figures within the text. –  yellowcap Aug 3 '12 at 14:11