3

I am wondering if I can manually set the caption number of an algorithm, or let the caption number of the algorithms in an article start from 2. The following is a MWE.

\documentclass[conference]{IEEEtran}

\usepackage[ruled]{algorithm}
\usepackage{algpseudocode}
%\usepackage{subfigure}
\usepackage[demo]{graphicx}
\usepackage{times}
\usepackage{amssymb}
\usepackage{url}
\usepackage{hyperref}
\usepackage{amsmath}
\usepackage{multirow}
\usepackage{graphicx}
\usepackage{setspace}
\usepackage{wrapfig}
\algnewcommand{\LineComment}[1]{\State \(\triangleright\) #1}

\begin{document}

%\title{xxx}
%
%\maketitle

\alglanguage{pseudocode}
\begin{algorithm}[h]
\large
\caption{\large Insert into CBF}
\label{Algorithm:insert}
\begin{algorithmic}[1]
\Procedure{$\mathbf{InsertItem}$}{item $x$}
    \LineComment{\emph{First insert $x$ into CBF}}
    \For {$i = 1 \to k$}
            \State $C_{f_i(x)\%N}$ ++
    \EndFor
\EndProcedure
\Statex
\end{algorithmic}
  \vspace{-0.4cm}%
\end{algorithm}

\end{document} 

Help is much appreciated!

4

This just amounts to adding

\setcounter{algorithm}{1}

just before \begin{algorithm} (one less than the desired number).

Notes.

  1. Your usage of \large is dubious. If you're using IEEEtran, then probably you're submitting a paper. Don't add formatting instructions like \large, because this will go against uniformity of the papers in the proceedings volume where the paper will appear. Also, with \large in the argument to \caption only the text and not the label will be in \large size.

  2. Say \usepackage{mathptmx} rather than \usepackage{times}, or the math will be in Computer Modern which is visually incompatible with Times. But, if Times is a requirement of the class, it will be automatically chosen by it. Again, if this is a submission, don't add formatting instructions like this.

  3. hyperref should be called last.

  • Thank you very much for your answer. In fact, I am indeed to submit a paper. For your notes, I have some questions. 1) If I cannot use \large or \small, how can I change the fonts in the algorithm? 2) The MWE in this question is only for this website, in fact I am using \usepackage{mathrsfs} and \usepackage{amsmath}. Will these two packages work fine? I know little about what you metioned. 3) This is only a submission, I will call hyperref if the paper is accepted. – Bloodmoon Jun 11 '13 at 10:06
  • You should not change any fontsizes, that is up to the journal to decide, not the author. (2) They will work fine. Regarding Times font, only add it if requested by the journal. You will save a lot of the journals time by not messing with layout, fonts, margins etc. – daleif Jun 11 '13 at 10:11
1

You can manually change the counter associated to the algorithm environment with:

\addtocounter{algorithm}{1}

Your code can be:

\documentclass[conference]{IEEEtran}
\usepackage[ruled]{algorithm}
\usepackage{algpseudocode}
\algnewcommand{\LineComment}[1]{\State \(\triangleright\) #1}
\begin{document}

\addtocounter{algorithm}{1}
\alglanguage{pseudocode}
\begin{algorithm}[h]
\large
\caption{\large Insert into CBF}
\label{Algorithm:insert}
\begin{algorithmic}[1]
\Procedure{$\mathbf{InsertItem}$}{item $x$}
  \LineComment{\emph{First insert $x$ into CBF}}
  \For {$i = 1 \to k$}
        \State $C_{f_i(x)\%N}$ ++
\EndFor
\EndProcedure
 \Statex
\end{algorithmic}
\vspace{-0.4cm}%
\end{algorithm}
\end{document} 
  • thank you, it works. I have voted for you, but egreg offered an answer earlier than you, so I cannot accept your answer as the solution. – Bloodmoon Jun 11 '13 at 9:57
  • Don't worry, egreg answer is more complete than mine. – bersanri Jun 11 '13 at 10:01

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.