2

I have 2 plots which in turn have 4 plots each, which I label as shown in the MWE. The code is modified (link) such that the caption of the figure reads:

Figure 1: (a)-(d) XYZ and (e)-(h) PQR

But doing so messes the subfigure references in the main text. I only get subfigure label (i.e., a,b, ... h) without the figure number. How to get multiple sub-references without affecting other sub-references?

MWE

\documentclass{article}
\usepackage{lipsum}

\usepackage{graphicx}
\usepackage[subrefformat=parens,labelformat=parens]{subfig}
\usepackage{cleveref}

\makeatletter 
\renewcommand\p@subfigure{} % no figure-number prefixes in cross-refs to subfigures
\makeatother
\crefformat{subfigure}{(#2#1#3)}
\crefrangeformat{subfigure}{(#3#1#4)--(#5#2#6)}

\begin{document}
\lipsum[1]

\begin{figure}
    \centering
    \subfloat{\label{fig_top_1}}\subfloat{\label{fig_top_2}}
    \subfloat{\label{fig_top_3}}\subfloat{\label{fig_top_4}}    
    \includegraphics[width=70mm,height=30mm]{example-image-a}

    \subfloat{\label{fig_bot_1}}\subfloat{\label{fig_bot_2}}
    \subfloat{\label{fig_bot_3}}\subfloat{\label{fig_bot_4}}    
    \includegraphics[width=70mm,height=30mm]{example-image-b}

    \caption{\cref{fig_top_1,fig_top_2,fig_top_3,fig_top_4} XYZ and 
             \crefrange{fig_bot_1}{fig_bot_4} PQR}
    \label{fig_top_bot}
\end{figure}

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit,
vestibulum ut, placerat ac, adipiscing vitae, felis. Curabitur dictum gravida
mauris \cref{fig_bot_3}. Nam arcu libero, nonummy eget, consectetuer id,
vulputate a, magna. Donec vehicula augue eu neque Fig.~\ref{fig_bot_3}. Pellentesque
habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas
Fig.~\subref*{fig_bot_3}.
\end{document}

If I comment the following statements, it works fine. But I require multiple sub-references of the figure to work also.

\makeatletter 
\renewcommand\p@subfigure{} % no figure-number prefixes in cross-refs to subfigures
\makeatother
\crefformat{subfigure}{(#2#1#3)}
\crefrangeformat{subfigure}{(#3#1#4)--(#5#2#6)}

Output

enter image description here

Output (commented statements)

enter image description here

0

1 Answer 1

1

I can do it, but not using cleveref.

The AUX file shows that the alternate definitions used by \subref{name} and \subref*{name} can also be accessed as \ref{sub@name} and \pageref{sub@name}. Perhaps someone more fluent with cleveref can get it to work with those references.

\documentclass{article}
\usepackage{lipsum}

\usepackage{graphicx}
%\usepackage{cleveref}
\usepackage{hyperref}
\usepackage[subrefformat=parens,labelformat=parens]{subfig}

\begin{document}
\listoffigures

\begin{figure}
    \centering
    \subfloat{\label{fig_top_1}\strut}\subfloat{\label{fig_top_2}\strut}
    \subfloat{\label{fig_top_3}\strut}\subfloat{\label{fig_top_4}\strut}    
    \includegraphics[width=70mm,height=30mm]{example-image-a}

    \subfloat{\label{fig_bot_1}\strut}\subfloat{\label{fig_bot_2}\strut}
    \subfloat{\label{fig_bot_3}\strut}\subfloat{\label{fig_bot_4}\strut}    
    \includegraphics[width=70mm,height=30mm]{example-image-b}

    \caption[\ref*{sub@fig_top_1}--\ref*{sub@fig_top_4} XYZ and 
             \ref*{sub@fig_bot_1}--\ref*{sub@fig_bot_4} PQR]%
            {\subref{fig_top_1}--\subref{fig_top_4} XYZ and 
             \subref{fig_bot_1}--\subref{fig_bot_4} PQR}
    \label{fig_top_bot}
\end{figure}

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit,
vestibulum ut, placerat ac, adipiscing vitae, felis. Curabitur dictum gravida
mauris \subref{fig_bot_3}. Nam arcu libero, nonummy eget, consectetuer id,
vulputate a, magna. Donec vehicula augue eu neque Fig.~\ref{fig_bot_3}. Pellentesque
habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas
Fig.~\subref*{fig_bot_3}.
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.