How to properly use subcaption with threeparttable

I'm trying to use the subcaption package inside the threeparttable environment, but can't get it work. I know there could be some issues with the two but I simply can't abandon the TPTT.

Apparently I get no error message but the sub-captions don't show up.

MWE:

\documentclass[a4paper]{memoir}
\usepackage{geometry,array,graphicx,float,caption}
\usepackage{subcaption}
\usepackage{threeparttable}

\begin{document}
\begin{figure}[ht]
\caption{Samples picture} \label{fig:picture_temp}
\centering
\begin{threeparttable}
\begin{subfigure}{0.45\textwidth}
\centering
\includegraphics[width=6cm]{example-image-b}
\caption{Before}
\label{fig:1a}
\end{subfigure}
~
\begin{subfigure}{0.45\textwidth}
\centering
\includegraphics[width=6cm]{example-image-c}
\caption{After}
\label{fig:1b}
\end{subfigure}
\begin{tablenotes}
\item Diference in samples over the range of temperatures.
\end{tablenotes}
\end{threeparttable}
\end{figure}
\end{document}


Sorry for the meme, I couldn't resist.

• gitlab.com/axelsommerfeldt/caption/issues/41
– user2574
Jan 2 '20 at 19:50
• Fixed with caption v3.4f. If someone had noticed me about this bug (which I found here by pure accident), it would have been fixed three years ago. ;)
– user2574
Jan 3 '20 at 10:59

Inside threeparttable the meaning of \@caption is changed. You want that inside of subfigure the meaning is as established by caption.

\documentclass[a4paper]{memoir}
\usepackage{geometry,array,graphicx,caption}
\usepackage{subcaption}
\usepackage{threeparttable}
\usepackage{etoolbox}

\makeatletter
\AtBeginEnvironment{subfigure}{\let\@caption\caption@original@caption}
\AtBeginDocument{\let\caption@original@caption\@caption}
\makeatother

\begin{document}

\begin{figure}[ht]
\caption{Samples picture} \label{fig:picture_temp}
\centering
\begin{threeparttable}
\begin{subfigure}{0.45\textwidth}
\centering
\includegraphics[width=6cm]{example-image-b}
\caption{Before}
\label{fig:1a}
\end{subfigure}
~
\begin{subfigure}{0.45\textwidth}
\centering
\includegraphics[width=6cm]{example-image-c}
\caption{After}
\label{fig:1b}
\end{subfigure}
\begin{tablenotes}
\item Difference in samples over the range of temperatures.
\end{tablenotes}
\end{threeparttable}
\end{figure}
\end{document}


The original meaning (as further modified by memoir) has to be saved at begin document. With \AtBeginDocument I restore that meaning, but only inside subfigure. You may need the same for tables.

• 1. \caption@caption is already defined (and used) by the caption package, so better use \@caption@original or something like this. 2. This patch does not fix \subcaption or \subcaptionbox inside threeparttable. 3. I just fixed this bug in caption v3.4f. 4. egreg, please inform me about such bugs so I get at least the chance of fixing it ;) (E-mail with subject "FYI" and SX link as body is sufficient.) Thanks!
– user2574
Jan 3 '20 at 11:04

I replaced the subcaption with the subfig package and used the \subfloat command, now it works like a charm with \tnotes in the (sub)caption.

Another option, without using threeparttable, can be found here using a simple \footnotesize inside figure environment.

\documentclass[a4paper]{memoir}
\usepackage{geometry,array,graphicx,float,caption}
\usepackage{subfig}
\usepackage{threeparttable}

\begin{document}
\captionsetup[subfloat]{position=bottom}
\begin{figure}[ht]
\caption{Samples picture} \label{fig:picture_temp}
\centering
\begin{threeparttable}
\subfloat[Before]{
\includegraphics[width=6cm]{example-image-b}
\label{fig:1a}
}
~
\subfloat[After \tnote{a}]{
\includegraphics[width=6cm]{example-image-c}
\label{fig:1b}
}
\begin{tablenotes}
\item Diference in samples over the range of temperatures.
\item[a] Calculated.
\end{tablenotes}
\end{threeparttable}
\end{figure}
\end{document}

• You should note that subfig may have problems with hyperref (that's why the general suggestion is to use subcaption instead in the first place). Jan 2 '19 at 15:08