2

I am trying to have subfigures within one figure lets say Figure 1 , below is the code I have now. The problem is it doesn't show after I compile the tex and under the figures the following caption Fig1a:fishfigure and Fig1a:catfigure it shows instead: the following (a)fishfigure (b)catfigure...

Does anyone know what the problem is?

\begin{figure}
\centering
\subfigure[fish figure]{%
\includegraphics[width=0.45\textwidth]{fish}%
\label{fig:fish}%
}
\hfil
\subfigure
[cat figure]{%
\includegraphics[width=0.45\textwidth]{cat}%
\label{fig:cat}%
}
\hfil
\subfigure
[dogfigure]{%
\includegraphics[width=0.45\textwidth]{dog}%
\label{fig:dog}%
       }
     \end{figure}
  • Hi, right now, i don't even understand the question. Can you provide a test case? This would say more than a thousand words. – Johannes_B Mar 25 '15 at 17:39
  • 1
    btw, right now, package subcaption is recommended to do the job. – Johannes_B Mar 25 '15 at 17:39
  • @Johannes_B The code I provided should put three figures as subfigures, the caption of the figures do not show Fig1(a) Fig1(b) Fig1(c), it shows instead (a) (b) (c)... – Henry Mar 25 '15 at 18:03
4

Use the subcaption package instead of the obsolete subfigure, redefine \thesubfigure and declare the desired format for the label using \DeclareCaptionLabelFormat:

A little example, using \subcaptionbox (another options would be to use the subfigure environment from subcaption):

\documentclass{article} 
\usepackage[demo]{graphicx} 
\usepackage{subcaption}

\makeatletter
\renewcommand\thesubfigure{\thefigure(\alph{subfigure})}
\renewcommand\p@subfigure{}
\makeatother
\DeclareCaptionLabelFormat{prefixsubfig}{Fig#1#2:}
\captionsetup[subfigure]{labelformat=prefixsubfig}

\begin{document} 

\begin{figure}
\centering
\subcaptionbox{fish figure\label{fig:fish}}{%
  \includegraphics[width=0.45\textwidth]{fish}}\hfill
\subcaptionbox{cat figure\label{fig:cat}}{%
\includegraphics[width=0.45\textwidth]{cat}}\par
\subcaptionbox{dogfigure\label{fig:dog}}{%
  \includegraphics[width=0.45\textwidth]{dog}}
\end{figure}

As we see in subfigures~\ref{fig:fish}, \ref{fig:cat}, and~\ref{fig:dog}

\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.

  • 1
    How many years will pass before subfigure goes into oblivion? :) – egreg Mar 25 '15 at 18:46

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.