[Tex/LaTex] Line numbering in algorithmic

algorithmicxalgorithmsbeamerline-numbering

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.

Best Answer

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:

Screenshot of Algorithm starting at line 2

\documentclass[12pt]{beamer}

\usepackage{algorithmic,algorithm,float}

\renewcommand\thealgorithm{}
\newcommand{\setalglineno}[1]{%
  \setcounter{ALC@line}{\numexpr#1-1}}

\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 equivalent) environments offered by algorithmicx. For these you have to use ALG@line instead of ALC@line though.