[Tex/LaTex] Numbers instead of letters with subfloat

numberingsubfloats

I have a document with a figure environment that looks like this:

\documentclass[a4paper,10pt]{article}
\usepackage{subfig}
\usepackage{tikz}

\makeatletter
\newbox\sf@box
\newenvironment{SubFloat}[2][]%
{\def\sf@one{#1}%
\def\sf@two{#2}%
\setbox\sf@box\hbox
\bgroup}%
{ \egroup
\ifx\@empty\sf@two\@empty\relax
\def\sf@two{\@empty}
\fi
\ifx\@empty\sf@one\@empty\relax
\subfloat[\sf@two]{\box\sf@box}%
\else
\subfloat[\sf@one][\sf@two]{\box\sf@box}%
\fi}
\makeatother

\begin{document}

\begin{figure}
\centering
\begin{SubFloat}
{\label{image1}}
\includegraphics[width=0.4\textwidth]{image1.jpg}
\end{SubFloat}
\qquad
\begin{SubFloat}
{\label{image2}}
\includegraphics[width=0.4\textwidth]{image2.jpg}
\end{SubFloat}
\end{figure}

\end{document}

(compiled with pdflatex)

LaTeX puts letters below each image ((a), (b), (c), etc..) and I want it to put numbers instead.

How could I do that?

Best Answer

For redefine the label for the subfig package use:

\renewcommand*\thesubfigure{\arabic{subfigure}} 

To keep the effect localized, use this within the figure environment as I have done below. As you can see in the subsequent use the labels are restored to using the default of (a) format:

enter image description here

If you want this to effect your entire document simply add the \renewcommand to the preamble.

Code:

\documentclass[a4paper,10pt]{article}
\usepackage[demo]{graphicx}% <----- remove "demo" option for real use
\usepackage{subfig}
\usepackage{tikz}
%\usepackage[paperheight=5.5in]{geometry}% For image capture

\makeatletter
\newbox\sf@box
\newenvironment{SubFloat}[2][]%
{\def\sf@one{#1}%
\def\sf@two{#2}%
\setbox\sf@box\hbox
\bgroup}%
{ \egroup
\ifx\@empty\sf@two\@empty\relax
\def\sf@two{\@empty}
\fi
\ifx\@empty\sf@one\@empty\relax
\subfloat[\sf@two]{\box\sf@box}%
\else
\subfloat[\sf@one][\sf@two]{\box\sf@box}%
\fi}
\makeatother

\begin{document}

\begin{figure}
\renewcommand*\thesubfigure{\arabic{subfigure}}
\textcolor{red}{With} \verb|\renewcommand*\thesubfigure{\arabic{subfigure}}| within the \verb|figure|:

\centering
\begin{SubFloat}
{\label{image1}}
\includegraphics[width=0.4\textwidth]{image1.jpg}
\end{SubFloat}
\qquad
\begin{SubFloat}
{\label{image2}}
\includegraphics[width=0.4\textwidth]{image2.jpg}
\end{SubFloat}
\end{figure}

\begin{figure}
\textcolor{red}{Without} \verb|\renewcommand*\thesubfigure{\arabic{subfigure}}|

\centering
\begin{SubFloat}
{\label{image1}}
\includegraphics[width=0.4\textwidth]{image1.jpg}
\end{SubFloat}
\qquad
\begin{SubFloat}
{\label{image2}}
\includegraphics[width=0.4\textwidth]{image2.jpg}
\end{SubFloat}
\end{figure}

\end{document}