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 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?

share|improve this question
2  
Using \renewcommand*\thesubfloatfigure{\themainfigure--\arabic{subfloatfigure}} should do it. Adjust the -- separator. While code snippets are useful in explanations, it is always best to compose a fully compilable MWE that illustrates the problem including the \documentclass and the appropriate packages so that those trying to help don't have to recreate it. While solving problems is fun, setting them up is not. Then those trying to help can simply cut and paste your MWE and get started on solving problem. –  Peter Grill Nov 13 '12 at 21:14
    
I'm sorry about the MWE, I know I should always include one with the question I just thought in this case it was a simple enough question not to need one (also I was lazy) Won't happen again. Quick follow-up question: where should I put the line you wrote? Above the figure? Will this also affect all the figures that come after that one? And, how should I adjust the --? Thank you very much! –  Gabriel Nov 13 '12 at 21:22
    
Even if it is simple it is still better to compose one -- not everyone is familiar every aspect of LaTeX, so that would help others. Plus with all software (well and hardware as well), unless it can be tested it you have to assume it does not work. As far as your question, if you want it to effect the entire document, put it in your preamble. If you want the effect localized, put it in a group, after \begin{figure} should work, but I can't test it without a MWE, so you'll have to do that... –  Peter Grill Nov 13 '12 at 21:25
    
You're right, I've added the MWE now. I still don't quite get how should I adjust the --. What do I do with those dashes? Regards. –  Gabriel Nov 13 '12 at 21:43

2 Answers 2

up vote 4 down vote accepted

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}
share|improve this answer
    
Excellent! Thank you so much! I've found it also works without the \usepackage[demo]{graphicx} line, could this be right? Regards. –  Gabriel Nov 13 '12 at 21:56
1  
The demo option was used as I did not have your figures. One of the other packages is including graphicx so that is why you don't need that line. If you are curious, you can add \listfiles before begin{document} and in the log file you will see the version of the packages that are being included. –  Peter Grill Nov 13 '12 at 22:02

If you add

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

in your preamble, then the subfigures will be numbered as (1), (2) and so on. However a \ref{label1} would print

11

which is obviously wrong. So you have also to add something like

\makeatletter
\renewcommand{\p@subfigure}{\thefigure--}
\makeatother

so that \ref{label1} will print

1--1

(change the separator as you wish).


Your definition of the SubFloat environment can be improved in a couple of ways.

  1. Standard LaTeX

    \makeatletter
    \newsavebox{\sf@box}
    \newenvironment{SubFloat}[2][]
      {\def\sf@one{#1}\def\sf@two{#2}%
       \begin{lrbox}{\sf@box}}%
      {\end{lrbox}%
       \ifx\@empty\sf@one
         \subfloat[\sf@two]{\box\sf@box}%
       \else
         \subfloat[\sf@one][\sf@two]{\usebox\sf@box}%
       \fi}
    \makeatother
    

    (Your test for emptiness add redundant tokens.)

  2. With xparse

    \usepackage{xparse}
    \makeatletter
    \newsavebox\sf@box
    \NewDocumentEnvironment{SubFloat}{ o m }
     {\begin{lrbox}{\sf@box}}
     {\end{lrbox}%
      \IfNoValueTF{#1}
       {\subfloat[#2]{\usebox{\sf@box}}}
       {\subfloat[#1][#2]{\usebox{\sf@box}}}%
     }
    \makeatother
    

    As you see you don't need any low level test: the package can distinguish by itself if the optional argument is not present.

share|improve this answer
    
Thank you for your answer @egreg but I'll admit that your definitions of the subfloat environment went way over my head since I didn't define it in my document, I'm just using a template I downloaded. I'm sure others (with a deeper LaTeX coding understanding) will find it very useful though. Cheers. –  Gabriel Nov 13 '12 at 22:51
    
@Gabriel That's the problem in copying templates from "untrusted" sources. That definition is rather poor LaTeX programming. –  egreg Nov 13 '12 at 22:53
    
Really?? That's odd, it comes from a pretty well known PhD template (in spanish) called Texis (gaia.fdi.ucm.es/research/texis) In any case it has worked rather well for me so far, so I'm very grateful to the authors for developing and making it available on line. Since I know pretty much nothing about LaTeX coding, I'll have to take your word on the poor coding. Regards and thanks again! –  Gabriel Nov 13 '12 at 23:00

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.