6

I use enumerating of figures within the section

\renewcommand{\thefigure}{\arabic{section}.\arabic{figure}}

however, when I use a reference to subfigure, instead of 1.1 (a) I get 1(a). How should I fix it?

Working example

\documentclass{article}
\usepackage{amsmath}
\usepackage{subfigure}
\usepackage{graphicx}
\usepackage{caption}
\renewcommand{\thefigure}{\arabic{section}.\arabic{figure}}

\makeatletter
\renewcommand{\thesection}{\arabic{section}.}
\renewcommand{\thesubsection}{\thesection\arabic{subsection}.}

\renewcommand{\section}{%
    \@startsection
        {section}{1}{0mm}
    {\baselineskip}
    {\baselineskip}
     {\fontsize{14}{14}\centering\bfseries\MakeUppercase}%       
   }
   \makeatother

\begin{document}
    \section{a}
    \begin{figure}[h] \label{fig:1} \centering
        \subfigure[]{\label{fig:11}
            \includegraphics[width=60mm]{1.png}}%
        \subfigure[]{\label{fig:12}
            \includegraphics[width=60mm]{2.png}}

        \caption{11 and 12}.
    \end{figure}
    \section{b}
        \ref{fig:11}
\end{document}
Gonzalo Medina
  • 505,128
Pavasaris
  • 2,971

1 Answers1

7

Instead of using the obsolete subfigure package you should use subfig or subcaption; here's your code using subfig:

\documentclass{article}
\usepackage{amsmath}
\usepackage{subfig}
\usepackage[demo]{graphicx}
\usepackage{caption}

\renewcommand{\thesection}{\arabic{section}.}
\renewcommand{\thesubsection}{\thesection\arabic{subsection}.}
\renewcommand{\thefigure}{\arabic{section}.\arabic{figure}}

\makeatletter
\renewcommand{\section}{%
    \@startsection
        {section}{1}{0mm}
    {\baselineskip}
    {\baselineskip}
     {\fontsize{14}{14}\centering\bfseries\MakeUppercase}%       
   }
%subsection
\renewcommand{\subsection}{%
    \@startsection
    {subsection}{1}{0mm}
   {\baselineskip}
   {\baselineskip}
   {\fontsize{14}{14}\centering\bfseries\MakeUppercase}%
   }
\makeatother

\begin{document}

\section{a}
\begin{figure}[h] 
\centering
\subfloat[]{\label{fig:11}%
  \includegraphics[width=60mm]{1.png}}\ %
\subfloat[]{\label{fig:12}%
  \includegraphics[width=60mm]{2.png}}
\caption{11 and 12}
\label{fig:1} 
\end{figure}

\ref{fig:11} or \ref{fig:1}\subref{fig:11}

\end{document}

enter image description here

As a side note, your redefinition for \thefigure won't reset the counter when a new section begins; if you want to reset the counter you could use

\@addtoreset{figure}{section}

inside \makeatletter, \makeatother, or

\numberwithin{figure}{section}

from the amsmath package, or

\counterwithin{figure}{section}

from the chngcntr package. Also note that, inside floating environments, \label must always appear after \caption (in your code \label is before \caption).

If, for some reason you need to stick to the subfigure package, then you can redefine \thesubfigure, \p@subfigure, and \@thesubfigure:

\documentclass{article}
\usepackage{amsmath}
\usepackage{subfigure}
\usepackage[demo]{graphicx}
\usepackage{caption}

\renewcommand{\thesection}{\arabic{section}.}
\renewcommand{\thesubsection}{\thesection\arabic{subsection}.}
\renewcommand{\thefigure}{\arabic{section}.\arabic{figure}}
\renewcommand{\thesubfigure}{\thefigure(\alph{subfigure})}
\makeatletter
\renewcommand{\p@subfigure}{}
\renewcommand{\@thesubfigure}{(\alph{subfigure})\hskip\subfiglabelskip}
\makeatother

\makeatletter
\renewcommand{\section}{%
    \@startsection
        {section}{1}{0mm}
    {\baselineskip}
    {\baselineskip}
     {\fontsize{14}{14}\centering\bfseries\MakeUppercase}%       
   }
%subsection
\renewcommand{\subsection}{%
    \@startsection
    {subsection}{1}{0mm}
   {\baselineskip}
   {\baselineskip}
   {\fontsize{14}{14}\centering\bfseries\MakeUppercase}%
   }
\makeatother

\begin{document}

\section{a}
\begin{figure}[h] 
\centering
\subfigure[]{\label{fig:11}%
  \includegraphics[width=60mm]{1.png}}\ %
\subfigure[]{\label{fig:12}%
  \includegraphics[width=60mm]{2.png}}
\caption{11 and 12}
\label{fig:1} 
\end{figure}

\ref{fig:11}

\end{document}

enter image description here

Gonzalo Medina
  • 505,128
  • I cannot use \numberwithin because of extra dot which appears with section. With this example I cannot use \setlength{\subfigtopskip}{1cm}, how should I change it? – Pavasaris Jun 05 '12 at 21:44
  • @Pavasaris yes, \subfigtopskip is not defined in subfig nor in subcaption; but do you really want to add 1cm before the subfigures? – Gonzalo Medina Jun 05 '12 at 21:57
  • I need 1cm between subfigures. And when I was prepering my report, it was defined like this, so now the view got broken and there will be so much work to repair it :( – Pavasaris Jun 05 '12 at 22:04
  • @Pavasaris I can't think of a quick fix now... anyways, it seems as if your best option for this document is to continue using subfigure; in my updated answer I've provided the necessary code with subfigure. However, for future documents, I recommend switching to either subfig or subcaption. – Gonzalo Medina Jun 05 '12 at 22:14
  • Thanks! I will know it for the next time, but maybe could you tell me what is the disatvantage of using subfigures? It's because of more difficult defining of true references? – Pavasaris Jun 06 '12 at 04:38
  • 1
    @Pavasaris no, the reason is more fundamental: subfigure is incompatible with really important packages such as hyperref and caption. – Gonzalo Medina Jun 07 '12 at 03:05