[Tex/LaTex] Issues referencing labels in measuredfigure environment

captionscross-referencingthreeparttable

As I want my captions to be the same width as my tables and figures I used the threeparttable package and the measuredfigure environment. However since, I have issues with referencing and labels of tables and figures in my text. Basically the figure/table number is replaced by ??. I've searched online but cannot find the appropriate help I need to fix this issue.

If I remove the caption and label from the measuredfigure environment and place it just above under \centering it works fine but the caption is no longer the width of the table/figure.

Many thanks

Egm1b

Here is WME

\documentclass[12pt,a4paper,oneside,english,oldfontcommands]{memoir}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[english]{babel}
\usepackage{xcolor}
\usepackage{csquotes}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{booktabs}
\usepackage{siunitx}
\usepackage{gensymb}
\usepackage{tikz}
\usepackage{wasysym}
\usepackage{tabularx}
\usepackage{cleveref}
\usepackage{threeparttable}

\usepackage{caption}
\captionsetup{justification   = raggedright,
singlelinecheck = false}
\newsubfloat{figure}% Allow subfloats in figure environment

\begin{document}

Below is summary table \Cref{tab:marker}

% Table generated by Excel2LaTeX from sheet 'Sheet6'
\begin{table}
    \centering
    \begin{measuredfigure}
    \caption{Caribou age groups at Nunalleq based on epiphyseal fusion  \label{tab:marker}}
        \begin{tabular}{lcc}
            \toprule
            Age group & NISP  & \% NISP \\
            \midrule
            Adult (fused) & 441   & 88.6\% \\
            Subadult (unfused) & 46    & 9.2\% \\
            Juvenile (unfused) & 11    & 2.2\% \\
            \midrule
            Total & 498   & 100.0\% \\
            \bottomrule
        \end{tabular}%
    \end{measuredfigure}
\end{table}%

And MWE code for figures

Here is example with reference to \Cref{marker2}

\begin{figure} 
\centering 
\begin{measuredfigure} 
\includegraphics[width=5cm]{figures/ch7_caribouwear1} 
\caption{This is a very long caption very long} 
\label{marker2} 
\end{measuredfigure} 
\end{figure}

\end{document}

Best Answer

It looks like a bug to me, measuredfigure loose the label even in a simple document. But normally you know the width of the image and so you don't need the environment and can use a minipage:

\documentclass[]{book}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}
\usepackage{threeparttable,graphicx}
\begin{document}
Here is example with reference to \ref{fig:marker1} %missing

\begin{figure}
\centering
\begin{measuredfigure}
\includegraphics[width=5cm]{example-image}
\caption{This is a very long caption very long\label{fig:marker1}}
\end{measuredfigure}
\end{figure}


Here is example with reference to \ref{fig:marker2}

\begin{figure}
\centering
\begin{minipage}{5cm}
\includegraphics[width=\linewidth]{example-image}
\caption{This is a very long caption very long\label{fig:marker2}}
\end{minipage}
\end{figure}

\end{document}
Related Question