1

I need a help, I wrote some algorithmic pseudocode in Latex and I want to show all the line numbers, no like on the image, every second.

Thank you for help.

How that look

Latex Code

\documentclass[a1paper,0pt]{article}
\usepackage{algorithm} 
\usepackage{algpseudocode}
\usepackage[paper=portrait,pagesize]{typearea}
\algdef{SE}[DOWHILE]{Do}{doWhile}{\algorithmicdo}[1]{\algorithmicwhile\ #1}%
\pagenumbering{arabic}
\begin{document}
\SetWatermarkAngle{109}
\begin{algorithm}
    \caption{BubbleSort()} 
    \begin{algorithmic}[2]
        \For {$i = 0 \textbf{ to } velkostPola-2$}
            \For {$j = 0 \textbf{ to } velkostPola-2$}
                \If {$pole[j] > pole[j+1]$} 
                \State $vymena(pole[j],pole[j+1])$
                \EndIf
            \EndFor
        \EndFor
    \end{algorithmic} 
\end{algorithm}
\begin{algorithm}
    \caption{InsertionSort()} 
    \begin{algorithmic}[2]
        \For {$i = 0 \textbf{ to } velkostPola-2$}
            \State $atributP \gets pole[i]$
            \State $atributJ \gets i-1$
            \While {$(atributJ >= 0)\textbf{ AND }(atributP < pole[atributJ])$}
                \State $pole[atributJ+1] \gets pole[atributJ]$
                \State $atributJ \gets atributJ-1$
            \EndWhile
            \State $pole[atributJ+1] \gets atributP$
        \EndFor
    \end{algorithmic} 
\end{algorithm}
\end{document}
1
  • Hi, welcome. Thanks for a fairly concise example. One minor thing though: it includes a command \SetWatermarkAngle which is not defined by any of the packages that are included, so in it's current form you get an error if you try it. Commented Apr 20, 2021 at 14:58

1 Answer 1

0

That is determined by the optional argument to the algorithmic environment. So when you do

\begin{algorithmic}[2]

that means every second line is numbered. To number all lines, use

\begin{algorithmic}[1]

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .