# Reference part of a figure (with or without cleveref)

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...

-

## migrated from stackoverflow.comDec 8 '11 at 19:50

This question came from our site for professional and enthusiast programmers.

There are automated ways of doing this rather than hard-coding the subfigure components after your reference. –  Werner Dec 8 '11 at 18:59
Welcome to TeX.sx! Your question was migrated here from Stack Overflow. Please register on this site, too, and make sure that both accounts are associated with each other, otherwise you won't be able to comment on or accept answers or edit your question. –  Torbjørn T. Dec 8 '11 at 19:55

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[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}


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