A strange behaviour: if I use the package subfigure and I add the caption in a font-changing environment, I have no figure number when I call the figure by reference.
MWE:
\documentclass{article}
\usepackage{graphicx}
\usepackage{subfig}
\begin{document}
\title{Test}
\section{Test}
Bla bla bla, please refer to Figure \ref{fig:flowchart}.
\begin{figure}
\centering
\includegraphics[width=0.9\textwidth]{imgs/global_imgs/ffsmFlowChart3.pdf}
\begin{footnotesize} \caption{FFSM++ Flowchart} \end{footnotesize}
\label{fig:flowchart}
\end{figure}
\end{document}
Results in:
If I remove subfig or I don't add the footnotesize, it works. Should I report it as a bug? Where?
Best Answer
The package
caption
that's automatically loaded bysubfig
(unless you pass it thecaption=false
option) makes further checks to the placement of\label
for a caption, in order to warn users making the common error of having the label before the caption.You have it after, but there's a catch: the
\caption
command is inside an environment, so the label it sets gets forgotten at\end{footnotesize}
. You indeed get the warningIf you remove
subfig
, you get no warning, but reference is wrong, as the following example shows:When
\label
is scanned, the most recent\current@label
is the one issued by\section{Test}
, because the one in the (inexistent)footnotesize
environment is forgotten.Use explicitly
caption
(it's better) and issueOne should avoid explicit markup like
\footnotesize
in the document as much as possible.