Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
share|improve this question
add comment

1 Answer

up vote 5 down vote accepted

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

share|improve this answer
    
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 5 '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 5 '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 5 '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 5 '12 at 22:14
1  
@Pavasaris no, the reason is more fundamental: subfigure is incompatible with really important packages such as hyperref and caption. –  Gonzalo Medina Jun 7 '12 at 3:05
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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