# Referring to a subfigure

I am writing up my thesis and I have some subfigures. When I typeset the code, the subfigures are labelled (a) and (b), however when I refer to the subfigures in the text, I get Figure 4.1.1 and 4.1.2 instead of 4.1(a) and 4.1(b). How do I change the code to get 4.1(a) instead of 4.1.1 in the text? The code I am using for the figures is shown below:

\begin{figure}[!htbp]

\begin{subfigure}{\textwidth}
\begin{center}
\includegraphics[width=0.8\textwidth,valign=t]{figures/chapter4/1.pdf}
\phantomcaption
\label{fig:1}
\end{center}
\end{subfigure}

\begin{subfigure}{\textwidth}
\begin{center}
\includegraphics[width=0.8\textwidth, valign=t]{figures/chapter4/2.pdf}
\phantomcaption
\label{fig:2}
\end{center}
\end{subfigure}

\caption{Graphs showing..}
\label{fig:Demand}
\end{figure}


Thanks

• Welcome to TeX.SE! Can you please make your code compilable? – Mensch Jul 26 '17 at 17:09
• – Marijn Jul 26 '17 at 17:13
• Which document class do you employ? How and/or where is the option valign=t defined? – Mico Jul 26 '17 at 17:45
• You wrote, "When I typeset the code, the subfigures are labelled (a) and (b)". Actually, since the code contains \phantomcaption directives, I don't see how it could generating captions labeled (a) and (b). Please clarify what's going on. – Mico Jul 26 '17 at 20:08
• Possible duplicate of Adding parentheses around subfig references – Henri Menke Jul 26 '17 at 23:26

Since you're using \phantomcaption statements, not "real" \caption statements, inside the subfigure environments, all you should need to do is issue the directive

\renewcommand\thesubfigure{(\alph{subfigure})}


in the preamble. (If you did use \caption statements, you'd also have to provide the directive \captionsetup[subcaption]{labelformat=simple}.)

A separate comment: You also ought to simplify and streamline the code in the figure environment, e.g., by having a single \centering statement and setting up the subfigure environments to occupy widths equal to 0.8\textwidth. The following shows how this might be done.

\documentclass{book} % is this right?
\usepackage[demo]{graphicx} % remove 'demo' option in real document
\usepackage{subcaption}
%\captionsetup[subcaption]{labelformat=simple} % not needed here
\renewcommand\thesubfigure{(\alph{subfigure})}

\begin{document}
\setcounter{chapter}{4} % just for this example

\begin{figure}[!htbp]
\centering
\begin{subfigure}{0.8\textwidth}
\includegraphics[width=\linewidth%,valign=t
]{figures/chapter4/1.pdf}
\phantomcaption
\label{fig:1}
\end{subfigure}

\medskip
\begin{subfigure}{0.8\textwidth}
\includegraphics[width=\linewidth%, valign=t
]{figures/chapter4/2.pdf}
\phantomcaption
\label{fig:2}
\end{subfigure}

\caption{Graphs showing \dots}
\label{fig:Demand}
\end{figure}

Cross-references to subfigures \ref{fig:1} and \ref{fig:2}.
\end{document}