# subfig reference layout

I have the following working example

\documentclass{article}
\usepackage[subrefformat=parens,labelformat=parens]{subfig}

\begin{document}

\textbf{Error} This should say Fig. 1\textbf{a}, not \ref{sf1}

\begin{figure}
\centering
\subfloat[Subfig 1]{\label{sf1} Contents of the sub-figure}
\subfloat[Subfig 2]{\label{sf2} Contents of the sub-figure}
\caption{\textbf{Error} This should only say \textbf{b}, not \ref{sf2}}
\label{fig}
\end{figure}
\end{document}


Basically my problem it stated in the MWE above.

1. When I reference a subfigure inside the figure caption, I want it only to refer to the bolded letter
2. When I reference a subfigure outside the figure caption, I want it to refer to the figure number + the bolded letter

1. You can use the command \subref instead of \ref. Please note that the command subref is fragile so you have either protect it inside caption or make the command robust.

2. Use \subref*.

\documentclass{article}
\usepackage[labelformat=parens]{subfig}
\DeclareSubrefFormat{subbold}{#1\textbf{#2}}%for \subref*
\DeclareCaptionListOfFormat{subbold}{\textbf{#2}}%for subref
\captionsetup[subfloat]{labelfont={bf},listofformat=subbold,subrefformat=subbold}
\usepackage{etoolbox}
\robustify\subref
\begin{document}

\textbf{Error} This should say Fig. 1\textbf{a}, not \subref*{sf1}

\begin{figure}[!ht]
\centering
\subfloat[Subfig 1]{\label{sf1} Contents of the sub-figure}

• 1: Thanks, you are right. However, that produces (b), not a bolded b as I desire. 2: The letter is not bolded by \ref. – BillyJean Nov 8 '13 at 9:32