# Subfigure referencing, wrong order

I have problems with subfigure referencing. When I reference the main figure, the labeling in the reference is correct, but when I try to reference the subfigure, I get figure X+1, which is kind of weird:

\documentclass[12pt]{article}
\pagestyle{plain}
\usepackage[english]{babel}
\usepackage{graphicx, hyperref, caption, float}
\usepackage{afterpage}
\usepackage{subfigure}
\usepackage{array}

\begin{document}

\begin{figure}[!htp]
\centering
\caption{Impulse responses to policy shocks}\label{fig:impulses to policy shocks}
\vspace{.05in}
\parbox{\linewidth}{\footnotesize%
This figure displays.....}
\subfigure[Something $\rightarrow$ Something.]{\label{fig:some_output}
\includegraphics[width=.45\textwidth]{slope_output.eps}}
\subfigure[Something else $\rightarrow$ something.]{\label{fig:something_output}
\includegraphics[width=.45\textwidth]{lvl_output.eps}}\\
\end{figure}
\end{document}


Then when i reference \hyperref[]{Figure \ref{fig:some_output}} I get the wrong figure number compared to what the simple reference \hyperref[]{Figure\ref{fig:impulses to policy shocks}}..

I tried a previous solution given here, but that did mess it up even more:

\makeatletter
\let\X@old@caption\caption
\def\X@caption@br[#1]#2{\X@old@caption[#1]{#2}\X@caption@minusone}
\def\X@caption@nobr#1{\X@old@caption{#1}\X@caption@minusone}
\def\caption{\@ifnextchar[\X@caption@br\X@caption@nobr}
\makeatother


Any help is highly appreciated.

• First of all: \usepackage{hyperref} should appear as the last package in almost any case. 2nd: You could use \ref{}, this should be sufficient and provide correct references and links. Using a different order of \usepackage messes up the correct linking.
– user31729
Aug 4 '14 at 8:22
• Another advice: subfigure has been superseeded by subfig. Package subcaption would be another alternative. Aug 4 '14 at 8:26
• Well, I put the \usepackage{hyperref} in the end of the preamble, but no luck. \ref{}vs \hyperref{} is no different. Also, I want the Figure X to be marked as a reference (colors and clickable) instead of only the number. Either way I still have issues provided your solution @ChristianHupfer. Regarding @Johannes_B solution, I did not understand what was meant by subfigure superseeded by subfig. Also I get ! Package subcaption Error: This package can't be used in cooperation (subcaption) with the subfigure package.. Aug 4 '14 at 11:32
• IIRC, subfigure does not use \refstepcounter, therefore hyperref has nothing to target. You need to use \hypertarget and \hyperlink. Aug 4 '14 at 13:14

Package subfigure has been superseded by package subfig a long time ago because of some messy stuff (as you have seen). An alternative to subfig is package subcaption by the author of caption. That means a maximum of compatibility.

Here is your example changed to use the subfigure environment, which is basically a minipage.

You can use the autoref command provided by hyperref to save some time. Remember to load package hyperref last in almost all cases.

\documentclass[12pt]{article}
\pagestyle{plain}
\usepackage[english]{babel}
\usepackage[demo]{graphicx}
\usepackage{subcaption}
\usepackage{hyperref}

\begin{document}
\begin{figure}[!htp]
\centering
\caption{Impulse responses to policy shocks}\label{fig:impulsesToPolicyShocks}
\begin{subfigure}{0.49\textwidth}
\centering
\includegraphics[width=.45\textwidth]{slope_output.eps}
\caption{Something $\rightarrow$ Something.}
\label{fig:someOutput}
\end{subfigure}\hfill
\begin{subfigure}{0.49\textwidth}
\centering
\includegraphics[width=.45\textwidth]{lvl_output.eps}
\caption{Something else $\rightarrow$ something.}
\label{fig:somethingOutput}
\end{subfigure}
\end{figure}
\autoref{fig:impulsesToPolicyShocks} contains
\autoref{fig:someOutput} and \autoref{fig:somethingOutput}
\end{document}


• Works like a charm. Thanks for tip on autoref Aug 4 '14 at 13:57