I am trying to reference a subfigure in my text but it is numbered incorrectly.
Here is a minimal working example:
\documentclass{scrartcl}
\usepackage[demo]{graphicx}
\usepackage{subfig}
\begin{document}
\begin{figure}
\caption{Two pictures side by side}
\label{img:both}
\subfloat[first picture]{
\includegraphics[width=5cm]{name}
\label{img:first}
}
\subfloat[second picture]{
\includegraphics[width=5cm]{name}
\label{img:second}
}
\end{figure}
This example shows that figure \ref{img:second} has a wrong reference number.
But the complete float is referenced correctly: \ref{img:both}
\end{document}
Best Answer
The
subfig
package is strongly dependent on the knowledge of the caption position -- is it above or below the figure or table?An except of the
subfig
package documentation:So usually this can be fixed using the correct
position
settings:However, KOMA-Script is some kind of special here because it has its own options and commands for specifying the main caption position. The
caption
/subfig
package respects (and supports) the KOMA-Script approach, making the code line\captionsetup[figure]{position=t}
not only superfluous but without any effect. (Seecaption
package documentation for details, section about "KOMA-Script".)So with KOMA-Script classes, one need to use the options and/or commands offered by KOMA-Script instead, at least for the main caption, for example with "captions=figureheading":
And voilà the reference will be correct, even with KOMA-Script. (Please note that because of a bug in KOMA-Script the option "captions=figureheading" used to have no effect. This was fixed in version 3.11b of KOMA-Script. If you have to deal with older versions of KOMA-Script and updating is not an option, try using
\captionabove
instead of\caption
.)