TransWikia.com

How to put a line number every line of algorithmic

TeX - LaTeX Asked by Skarab on April 15, 2021

I am looking for a way to have a number for every line in algorithmic:

documentclass{article}
usepackage{algorithm} 
usepackage{algorithmic}
begin{document}
    begin{algorithm}
        caption{Some alg}
        begin{algorithmic}
            REQUIRE a,b, c
            STATE d = a + b + c
            STATE d = d/2
            STATE d = d/3
            RETURN d
        end{algorithmic}
    end{algorithm}
end{document}

I would like to have:

 Require: a,b,c
1 d = a + b + c
2 d = a + b + c
3 d = d/2
4 d = d/3
  return d

One Answer

According to the manual you can do this the following way:

An optional argument to the begin{algorithmic} statement can be used to turn on line numbering by giving a positive integer indicating the required frequency of line numbering. For example, begin{algorithmic}[5] would cause every fifth line to be numbered.

Obviously, begin{algorithmic}[1] causes a number for every line.

Correct answer by Jannis Pohlmann on April 15, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP