# subcaption package incompatible with memoir class?

When I try to compile a document with the memoir class and the subcaption package I get the following error:

! Package subcaption Error: This package can't be used in cooperation with the subfig package.

I presume this is because the memoir class loads the subfig package. Is that correct?

Is there a way to make them work together?

-
Beyond what Harish says below, memoir also has built-in support for subfloats in general. See section 10.9 (Subcaptions) of the memoir manual -- no extra packages required, depending on your needs. – Mike Renfro Mar 21 '12 at 16:06

The subfig and subcaption packages can not be used in cooperation with each other. Instead, you can usecaption package with subfig to add some flavor to the captions and subcaptions (or you can use caption along with subcaption (which gives a subfigure command also).

\documentclass{memoir}
\usepackage[demo]{graphicx} % remove [demo] in your file
\usepackage{subfig} % for subfigures
\usepackage{caption}
\usepackage{lipsum}

\captionsetup[figure]{labelfont={bf,small},textfont={it,small}}
\captionsetup[subfloat]{labelfont={bf,small},textfont={it,small},
subrefformat=parens} %<-----designing subcaption
\newcommand{\myfigref}[2]{~\ref{#1}.\subref{#2}}% <---- a new macro for referring to a subfigure
%
\begin{document}
%=========================
\chapter{First chapter}
\lipsum[1-4]
%=========================
\begin{figure}[ht]
\includegraphics[width=1\textwidth]{my figure}
\caption{My single picture}\label{fig:figures}
\end{figure}
%=========================
\begin{figure}[ht]
\centering
\subfloat[My first picture]{\label{fig:mdleft}{\includegraphics[width=0.4\textwidth]{my figure}}}\hfill
\subfloat[My second picture]{\label{fig:mdright}{\includegraphics[width=0.4\textwidth]{my figure}}}
\caption{My two big pictures}
\label{fig:subfigures}
\end{figure}
%===========================
From figure~\ref{fig:subfigures}.\subref{fig:mdleft}, we can see a small cat, in
\myfigref{fig:subfigures}{fig:mdright} both can be used to refer figures.
\end{document}


-
Thanks! How would you modify the example above to be able to "subref" to the subfigure captions? For example, in the text, I would like to say: In Figure 2.(a) we show ... . Also, why is it that your Figures start with the numbers 0.1 and 0.2? How would make that to go with the numbers 1, 2 etc.? – Amelio Vazquez-Reina Mar 21 '12 at 16:00
@roseck See my edited answer. – Harish Kumar Mar 21 '12 at 23:48

As Mike Renfro said in his comment, memoir already includes support for subfigures and subcaptions and there is no need to load packages subfig and caption. With next code you will reproduce Harish's result.

\documentclass{memoir}
\usepackage[demo]{graphicx} % remove [demo] in your file

\usepackage{lipsum}

% You need a newsubfloat element to use subcaption
\newsubfloat{figure}

% Command to set caption styles
\captionnamefont{\bfseries\small}
\captiontitlefont{\itshape\small}
\subcaptionlabelfont{\bfseries\small}
\subcaptionfont{\itshape\small}

%
\begin{document}
%=========================
\chapter{First chapter}
\lipsum[1-4]
%=========================
\begin{figure}[ht]
\includegraphics[width=1\textwidth]{my figure}
\caption{My single picture}\label{fig:figures}
\end{figure}
%=========================
\begin{figure}[ht]
\centering
\subbottom[My first picture\label{fig:mdleft}]%
{\includegraphics[width=0.4\textwidth]{my figure}}\hfill
\subbottom[My second picture\label{fig:mdright}]%
{\includegraphics[width=0.4\textwidth]{my figure}}
\caption{My two big pictures}
\label{fig:subfigures}
\end{figure}
%===========================

%In next paragraph look at differences between \ref{subfigurelabel},
%\subcaptionref{subfigurelabel} and \subcaptionref*{subfigurelabel}
%
In figure~\ref{fig:subfigures} we can see a small cat
(\ref{fig:mdleft} or \subcaptionref*{fig:mdleft}) and
something else in \ref{fig:mdright} or \subcaptionref{fig:mdright}.
\end{document}


\newsubloat{figure} declares a new subfloat element which allows to use \subbottom commands. Now \ref{subfigurelabel} equals to '1.2(a)' while \subcaptionref{subfigurelabel} equals to '(a)' (with font attibutes) and the undocumented \subcaptionref* resets sublabel to normal font.

-
Thanks a lot!! Worked like a charm! :) – rmbianchi Aug 31 '12 at 14:05

Unfortunately the error message is misleading (*), and the memoir document class is not working with my subcaption package yet.

But you can give

\let\subcaption\relax
\let\subfloat\relax


a try, just place this code before loading the subcaption package.

(*) I have just changed that, so with future versions one will get the error message "Incompatible document class or package detected" instead.

-
I hope to be working on memoir soon again. Drop me an email, then er can see what can be done from the memoir side of things. – daleif Mar 22 '12 at 9:52
Finally I have found some time to take a closer look at this issue, and it seems that I was able to adapt the subcaption package for usage with the memoir document class. I'll release it with the upcoming version 3.3 of the caption package within the next weeks. – Axel Sommerfeldt Apr 10 '12 at 6:57
Thanks Axel for your work. Anyway I would like to let you know that while trying to compile memoir+subcaption with MacTex 2012 I still get the error from subcaption. – rmbianchi Aug 31 '12 at 13:06
Unfortunately the new version of the caption package bundle is not ready yet :-( See also: tex.stackexchange.com/a/27437/2574 – Axel Sommerfeldt Sep 1 '12 at 6:19