# Change caption number of an algorithm

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!

\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. Jun 11, 2013 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. Jun 11, 2013 at 10:11
• It seems that after setting the counter, the reference number does not change. For example, if the algorithm is labeled as \label{alg}, then \ref{alg} still displays 1 rather than 3. How to solve this problem? Jun 8, 2020 at 4:43
• @zbh2047 The \label must go inside \caption or after it. Jun 8, 2020 at 7:39

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

\addtocounter{algorithm}{1}


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

\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. Jun 11, 2013 at 9:57
• Don't worry, egreg answer is more complete than mine. Jun 11, 2013 at 10:01
\renewcommand{\thealgorithm}{3.\arabic{algorithm}}
\setcounter{algorithm}{0}


The above command will rename it to Algorithm 3.1 and so on.

If you want, may delete the \arabic{algorithm} command to have it as algorithm 3.