In case you installed TeX Live from the packages of a Linux distro: Most distros split less-used LaTeX-packages into separate (Linux-distro)-packages. From the link in your question I assume that you are running Arch Linux. In this case you need to install the texlive-latexextra
package which contains subfigure.sty. If you are using a different distro, the necessary package might be named differently (e.g. texlive-latex-extra
in Debian/Ubuntu).
Also, as Peter notes, the subfigure
package is depreciated.
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:
3.1.5 The Caption Position Option
The caption package ‘position’ option specifies whether the caption appears before or
after the figure or table. This can adjust the relative spacing used to separate the float
from the surrounding text. However, for the subfig package, it serves a more important
function. That is it determines if the sub-floats belong to or are associated with the last \caption command to be given, or the next one to be executed sometime in the
future. If you find that you sub-references do not agree with the top-level labels, than
you may need to specifically set the ‘position’. This is best done when loading the
caption package, but may be done at anytime with the \captionsetup command.
So usually this can be fixed using the correct position
settings:
\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{subfig}
% Telling the subfig package the desired caption positions
\captionsetup[figure]{position=t}
\captionsetup[subfigure]{position=b}
\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}
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. (See caption
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":
\documentclass[captions=figureheading]{scrartcl}
\usepackage[demo]{graphicx}
\usepackage{subfig}
% Telling the subfig package the desired caption position
\captionsetup[subfigure]{position=b}
\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}
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
.)
Best Answer
When compiling your MWE with
pdflatex
I get the errorWhatever that means … (I have used neither
caption
norsubcaption
before.)Apparently
caption
is confused when you use\ContinuedFloat
in afigure
environment when the preceding one doesn’t had a\caption
; which isn’t very surprising because there isn’t much to continue. To fix this, add a\phantomcaption
to the firstfigure
environment. [See Axel Sommerfeldt's comment.]If you do want to include a caption in the first
figure
environment, of course, you must not use\phantomcaption
.Code
Note that I have removed every reference to an external graphic because
I also removed
\usepackage{caption}
, it does get already loaded bysubcaption
.The
chngcntr
package does not interfere with this MWE.Output