# Line numbering in algorithmic

I want to change the first number of the line numbering in my algorithm, but how is it done? This is my example:

\documentclass[12pt]{beamer}
\usepackage{amsmath, amsfonts, amssymb, amsthm}
\usepackage{algorithmic, algorithm}
\usepackage{float}
\renewcommand\thealgorithm{}

\begin{document}
\begin{frame}[t, fragile]
\frametitle{...}
\begin{algorithm}[H]
\caption{...}
\begin{algorithmic}[1]
\STATE ...
\end{algorithmic}
\end{algorithm}
\end{frame}
\end{document}


The first state should be numbered with 2 for example.

-
Welcome to TeX.sx! – percusse Nov 2 '12 at 16:49

The line number in algorithmic (from the algorithms bundle) is governed by the counter ALC@line. The following MWE defines \setalglineno{<num>} which allows you to modify the number of any line in your algorithmic:

\documentclass[12pt]{beamer}
\usepackage{algorithmic, algorithm}% http://ctan.org/pkg/algorithms
\usepackage{float}% http://ctan.org/pkg/float
\renewcommand\thealgorithm{}
\makeatletter
\newcommand{\setalglineno}[1]{%
\setcounter{ALC@line}{\numexpr#1-1}}
\makeatother
\begin{document}
\begin{frame}[t, fragile]
\frametitle{...}
\begin{algorithm}[H]
\caption{...}
\begin{algorithmic}[1]
\setalglineno{2}% Set following line number to 2
\STATE ...
\end{algorithmic}
\end{algorithm}
\end{frame}
\end{document}


In fact, \setalglineno{<num>} sets ALC@line to <num>-1, since the algorithm is set in a list, where each line counter is incremented before it is set. So, technically, to obtain a line numbered 2, you need to set the counter value to 1.

A similar setup would be used within the algpseudocode (or similar) environments offered by algorithmicx.

-
Is it ALG@line instead of ALC@line? – hengxin Oct 31 '13 at 3:39
@hengxin: It's ALC@line. Try the other one and you'll see why. – Werner Oct 31 '13 at 4:46
ALG@line (not ALC@line) works for me. Maybe it is because that I use algpseudocode + algorithmicx + algorithm environments. – hengxin Oct 31 '13 at 5:22
@hengxin: Yes, there's a difference. – Werner Oct 31 '13 at 6:00
Hi, thanks for an answer. I have a follow up question. What changes should be done to your code, to enable me to pass \ref{} as a parameter to \setalglineno? I want to make a \label at the last line of the first algorithm and the second one would continue its numbering from there. – jutky Jul 19 '14 at 20:13