1

I would like to use \autoref{fig:subfig:a}, but I don't get the figure number by simply typing this. My code is:

\documentclass{article}
\usepackage{amssymb,amstext,amsmath,latexsym,mathtools}
\usepackage{pdfpages}

\usepackage{graphicx}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{float}

\usepackage{hyperref}

\begin{document}

\section{Aya}

\autoref{fig:ABC:a}

\begin{figure}[H]
\centering
\subfloat[this is ...]{
\label{fig:ABC:a}
\includegraphics[width=0.45\linewidth]{ABC1.pdf}}
\hspace{0}
\subfloat[this is ...]{
\label{fig:ABC:b}
\includegraphics[width=0.45\linewidth]{ABC2.pdf}}\\[20pt]
\subfloat[...]{
\label{fig:ABC:c} 
\includegraphics[width=0.45\linewidth]{ABC3.pdf}}
\hspace{0}
\subfloat[...]{
\label{fig:ABC:d}
\includegraphics[width=0.45\linewidth]{ABC4.pdf}}
\caption{abcd}
\label{fig:ABC} %% label for entire figure
\end{figure}

\end{document} 

What should I add to display the number of the figure correctly?

3
  • Welcome to TeX.SE! Please consider augmenting your code so that it becomes a compilable MWE (minimum working example) that generates the problem behavior you say you're encountering. The MWE should take care of loading all required latex packages -- and, ideally, only the required latex packages.
    – Mico
    Jun 27 '12 at 12:59
  • The modified code generates an error message, that the command \subfloat isn't recognized. I gather that this is a macro that's provided by the subfig package -- which, by the way, is not loaded in your example code. Given that the subfig package is quite obsolete, though, you should consider using the subfigure environment that's provided by the subcaption package. An example of how to use this environment is provided in the answer I've given.
    – Mico
    Jun 27 '12 at 16:20
  • Thank you very much. but the exact code I put compiles with me, with typing 'return' once. and the pictures appear. Anyway, thank you very much for your information. I will try to use your suggested answer.
    – Aya
    Jun 27 '12 at 16:52
2

Here's a solution that requires only the capabilities provided by the caption and subcaption packages. Note the repeated use of the subfigure environment within a figure environment. To have the captions placed below the graphics, just move the subfigures' \caption commands to below the \includegraphics statements.

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage[font=small,labelfont=bf]{caption}
\usepackage{subcaption}

\usepackage{hyperref}
\begin{document}

\begin{figure}

\begin{subfigure}{0.48\textwidth}
\centering
\caption{First subfigure} \label{fig:ABC:a}
\includegraphics[width=\linewidth]{fig1.pdf}
\end{subfigure}
\hspace*{\fill}
\begin{subfigure}{0.48\textwidth}
\centering
\caption{Second subfigure}\label{fig:ABC:b}
\includegraphics[width=\linewidth]{fig2.pdf}
\end{subfigure}
\caption{Overall caption}
\label{fig:ABC}
\end{figure}

Here's a cross-reference to \autoref{fig:ABC}, and here's one to \autoref{fig:ABC:b}.
\end{document}

enter image description here

5
  • thank you very much. however, I remember I used 'subfloat' instead of 'subfigure' for a reason. Isn't there any difference?
    – Aya
    Jun 27 '12 at 14:42
  • I couldn't get your code to compile -- there's probably a package that you load but isn't listed in the example you provide. (That's also why people are usually encouraged to post a complete MWE rather than code fragments.) Please consider augmenting you code to make it a compilable MWE, and I'll take another look.
    – Mico
    Jun 27 '12 at 14:49
  • The figures now appear at the end of the document.. do you know why? thanks
    – Aya
    Jun 30 '12 at 5:34
  • 1
    Do you maybe have one or more float environments set up with [h] position specifier? Please see Frank Mittelbach's essay (at tex.stackexchange.com/a/39020/5001) for much more information on LaTeX's float positioning algorithms and, in particular, why it's usually not a good idea to use the [h] specifier. Alternatively, have you maybe loaded the endfloat package?
    – Mico
    Jun 30 '12 at 18:15
  • oh! thank you very much.. I probably wrote this in a hurry.. thank you for your information. I did solve the problem at the same time. I just deleted the 'float' package because of using your suggestion \subfigure instead of \subfloat
    – Aya
    Jul 1 '12 at 2:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.