[Tex/LaTex] Reference part of a figure (with or without cleveref)

cleverefcross-referencingsubfloats

I have a figure with multiple parts (a, b, c, etc.) and in the text I would like to have a reference to the figure with the letter of the part (i.e. fig 1(b) ). Is there a way to pass this to \cref{} or \ref{} in order to have it do this?

EDIT: So this turned out to be a dumb question. I forgot \ref{} returns just the number, so this is easily done using

Figure \ref{fig:1}a says...

Best Answer

If you are using the subfig or the subcaption package to build your subfloats, in addition to the standard \ref command, you can also use \subref to reference a particular subfloat. The standard \ref command returns a label built by concatenating the float number and \thesubfloat; the \subref command only returns the label for the subfloat:

\documentclass{article}
\usepackage{subfig}

\begin{document}

\begin{figure}
\centering
\subfloat[test1\label{sub:1}]{A}\qquad
\subfloat[test2\label{sub:2}]{B}
\caption{General caption}
\label{fig:test}
\end{figure}

Figure~\ref{fig:test} and subfigures~\subref{sub:1} and \subref{sub:2}

Figure~\ref{fig:test} and subfigures~\ref{sub:1} and \ref{sub:2}

\end{document}

enter image description here

Using cleveref you can use \crefname, \Crefname to change the default names used for subfigures:

\documentclass{article}
\usepackage{subfig}
\usepackage{cleveref}

\crefname{subfigure}{subfigure}{subfigures}
\Crefname{subfigure}{Subfigure}{Subfigures}

\begin{document}

\begin{figure}
\centering
\subfloat[test1\label{sub:1}]{A}\qquad
\subfloat[test2\label{sub:2}]{B}
\caption{General caption}
\label{fig:test}
\end{figure}

\Cref{fig:test} and \cref{sub:1,sub:2}

\Cref{fig:test} and \cref{sub:1,sub:2}

\end{document}
Related Question