[Tex/LaTex] Figure numbering with section number, problem with subfigure

floatsnumberingsubfloats

I changed my figure numbering to section-style numbering for my thesis:

\numberwithin{figure}{section}

That's fine, but the only problem that remains in the following MWE:

\documentclass[english,12pt]{article}
\usepackage{float}
\usepackage{subfigure}

\begin{document} 

\begin{figure}[H]
\centering
\subfigure[First temperature cycle. We measured additionally at +1$^{\circ}$C.]{
\includegraphics[width=0.98\textwidth]{./figures/mu_vs_v_1st.pdf}
\label{fig:mu_vs_v_1st}
}\\
\subfigure[Second temperature cycle. Note the difference to the first cycle of     1$^{\circ}$C in the highest temperature measured.]{
\includegraphics[width=0.98\textwidth]{./figures/mu_vs_v_2nd.pdf}
\label{fig:mu_vs_v_2nd}
}
\label{fig:mu_vs_v}
\end{figure}

\end{document}

Here I get the section style numbering for the figure as a whole (Fig. 5.3 – the figure being the third one in Section 5) but I get Fig. 7(a) and 7(b) for referral straight to the subfigures (the figure being the seventh in the whole thesis).

What should I change to get Fig. 5.3(a) and 5.3(b) for the subfigures as well? Thanks in advance!

Best Answer

You can redefine \p@subfigure which controls the prefix used for the cross-references to subfigures:

\documentclass[english,12pt]{article}
\usepackage[demo]{graphicx}
\usepackage{float}
\usepackage{amsmath}
\usepackage{subfigure}

\numberwithin{figure}{section}

\makeatletter
\renewcommand\p@subfigure{\thefigure}
\makeatother

\begin{document} 

\section{Test Section}

A reference to subfigures~\ref{fig:mu_vs_v_1st} and~\ref{fig:mu_vs_v_2nd}

\begin{figure}[H]
\centering
\subfigure[First temperature cycle. We measured additionally at +1$^{\circ}$C.]{%
\includegraphics[width=0.98\textwidth]{./figures/mu_vs_v_1st.pdf}
\label{fig:mu_vs_v_1st}%
}\\
\subfigure[Second temperature cycle. Note the difference to the first cycle of     1$^{\circ}$C in the highest temperature measured.]{%
\includegraphics[width=0.98\textwidth]{./figures/mu_vs_v_2nd.pdf}
\label{fig:mu_vs_v_2nd}
}
\caption{test figure with subfigures}
\label{fig:mu_vs_v}
\end{figure}

\end{document}

enter image description here

The demo option for graphicx simply replaces actual figures with black rectangles; do not use that option in your actual document.

By the way, subfigure is an obsolete package. You should consider using subfig or subcaption instead.

Using the subfig package has an additional advantage: you don't need to redefine \p@subfigure since internally the package does this for you:

enter image description here

\documentclass[english,12pt]{article}
\usepackage[demo]{graphicx}
\usepackage{float}
\usepackage{amsmath}
\usepackage[listofformat=subparens]{subfig}

\numberwithin{figure}{section}

\begin{document} 

\section{Test Section}

A reference to subfigures~\ref{fig:mu_vs_v_1st} and~\ref{fig:mu_vs_v_2nd}. And another reference to subfigures~\ref{fig:mu_vs_v}\subref{fig:mu_vs_v_1st} and~\ref{fig:mu_vs_v}\subref{fig:mu_vs_v_2nd}

\begin{figure}[H]
\centering
\subfloat[First temperature cycle. We measured additionally at +1$^{\circ}$C.\label{fig:mu_vs_v_1st}]{%
\includegraphics[width=0.98\textwidth]{./figures/mu_vs_v_1st.pdf}}\\
\subfloat[Second temperature cycle. Note the difference to the first cycle of $1^{\circ}$C in the highest temperature measured.\label{fig:mu_vs_v_2nd}]{%
\includegraphics[width=0.98\textwidth]{./figures/mu_vs_v_2nd.pdf}}
\caption{test figure with subfigures}
\label{fig:mu_vs_v}
\end{figure}

\end{document}