6

The following code compiles and acts as you would expect:

\documentclass[12pt]{report}

%\usepackage{hyperref}
\usepackage{subfig}

\begin{document}

\begin{figure}
\centering
\renewcommand{\thefigure}{$\dag$}
\subfloat[Sub-dagger]
{
\label{subfloat:first}
Hello there my good sport
}%
\qquad
\subfloat[Sub-dagger the other]
{
Hello again nice to see you
}
\caption{Daggered figure}
\label{fig:dag}
\end{figure}

Figure \ref{fig:dag} shows two things... one of them is sub-figure \ref{subfloat:first}.

\listoffigures

\end{document}

However, when %\usepackage{hyperref} is uncommented, the following error is given:

! TeX capacity exceeded, sorry [input stack size=5000].
\curr@fontshape ->\f@encoding 
                              /\f@family /\f@series /\f@shape 
l.11 \subfloat
              [Sub-dagger]
!  ==> Fatal error occurred, no output PDF file produced!

No error occurs if no subfloats are in the figure, either. The error occurs even if \listoffigures is commented out.

A remark: if $\dag$ is replaced by $a$, or by ABC, the code compiles fine. It seems like there is some issue with the amount of memory $\dag$ takes, which is strange to me.

Gonzalo Medina
  • 505,128

1 Answers1

7

Instead of using subfig you could use the subcaption package:

\documentclass[12pt]{report}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{hyperref}

\begin{document}

\begin{figure}
\centering
\renewcommand{\thefigure}{$\dag$}
\subcaptionbox{First subfigure\label{subfloat:first}}{Hello there my good sport}\qquad
\subcaptionbox{Second subfigure\label{subfloat:second}}{Hello again nice to see you}
\caption{Daggered figure}
\label{fig:dag}
\end{figure}

Figure \ref{fig:dag} shows two things... one of them is sub-figure \ref{subfloat:first}.

\listoffigures

\end{document}

enter image description here

On a side note, except for some exceptions, hyperref should be the last package to load.

If switching to subcaption is not an option, then you can use the following:

\documentclass[12pt]{report}
\usepackage{subfig}
\usepackage{hyperref}

\makeatletter
\newcommand\specialcaption[1]{%
  \@namedef{the\@captype}{#1}%
  \addtocounter{\@captype}{-1}\caption}
\makeatother

\begin{document}

\begin{figure}
\centering
\makeatletter
\def\p@subfigure{$\dag$} 
\makeatother
\subfloat[Sub-dagger]
{%
\label{subfloat:first}
Hello there my good sport
}%
\qquad
\subfloat[Sub-dagger the other]
{%
Hello again nice to see you
}
\specialcaption{$\dag$}{Daggered figure}
\label{fig:dag}
\end{figure}

Figure \ref{fig:dag} shows two things... one of them is sub-figure \ref{subfloat:first}.

\listoffigures

\end{document}

enter image description here

Notice the spurious blank spaces that I removed by using the % character.

Gonzalo Medina
  • 505,128