I have a figure with 6 subfloat figures.

    \subfloat[]{\includegraphics{fig1}\label{fig1}} \hfill
    \subfloat[]{\includegraphics{fig2}\label{fig2}} \hfill
    \subfloat[]{\includegraphics{fig3}\label{fig3}} \hfill
    \subfloat[]{\includegraphics{fig4}\label{fig4}} \hfill
    \subfloat[]{\includegraphics{fig5}\label{fig5}} \hfill
    \subfloat[]{\includegraphics{fig6}\label{fig6}} \hfill
    \caption{Analysis of color variation}

I am trying to reference subfigures in figure caption and in text. Currently, i am using \ref to reference figures. I need two styles of references, one separated by hyphen and one separated by comma.

I need the caption of the figure as: Analysis of color variation. (a-c) represent color. (d-f) represent contrast, and (a-c) represent gamma.

In text, I need to reference ...as shown in Fig. 12(a, d), (b, e) and (c, f) respectively... Fig. 13(a) shows...

Any idea how to achieve this? Any help will be highly appreciated.

  • 2
    Please do not post such fragments only. You may have a look into cleveref which will provide customized cross-referencing formats
    – user31729
    Commented Dec 27, 2017 at 12:26

1 Answer 1


This can be accomplished with cleveref.



  \tl_set:Nx \l_tmpa_tl { #1 }
  \tl_item:Nn \l_tmpa_tl { -1 }

\newcommand{\includegraphics}[1]{{\Huge #1}} % just for the example


As shown in \cref{fig_main} \cref{fig1,fig4}, \cref{fig2,fig5}, and
\cref{fig3,fig6} respectively.


\caption[Analysis of color variation]{%
  Analysis of color variation;
  \cref{fig1,fig2,fig3} represent color,
  \cref{fig4,fig5,fig6} represent contrast,
  and \cref{fig1,fig2,fig3} represent gamma.%



The command \includegraphics has been given a suitable definition to emulate printing figures I don't have; you'll remove this definition and use graphicx, of course.

The main problem is to get subfigures referenced only with the letter, which requires the \onlyletter trick. The rest is standard cleveref.

enter image description here

  • Thank you very much @egreg, you saved the day. It works like a charm... Thanks dearie :)
    – Raja Ayaz
    Commented Dec 27, 2017 at 13:42
  • +1. The \onlyletter trick is really neat. The same result could have been achieved, arguably somewhat more simply, by running \makeatletter \renewcommand\p@subfigure{} \makeatother, i.e., by un-setting the definition of \p@subfigure. Of course, the cleveref-related setup would still be needed.
    – Mico
    Commented Dec 27, 2017 at 17:30
  • @Mico You're right, but perhaps the whole reference is needed in other situations
    – egreg
    Commented Dec 27, 2017 at 17:53
  • @egreg exactly, that was the case. I had too many whole references besides this in the text.
    – Raja Ayaz
    Commented Dec 27, 2017 at 18:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .