3

I want to write an algorithm using the Latex algorithm generator. Can anyone help me in this case? A sample is given below.

Any sort of help would be highly appreciated. enter image description here

1
  • 4
    Welcome to TeX.SX! What have you tried so far? Please provide a minimal working example (MWE) of your current attempt for us to work on.
    – epR8GaYuh
    Commented Jun 12, 2021 at 7:25

1 Answer 1

13

You can use the package

\usepackage[options]{algorithm2e}

for instance

\usepackage[linesnumbered,commentsnumbered,ruled,vlined]{algorithm2e}

Then write your algorithm like

\IncMargin{1em}
\begin{algorithm}[htbp]
\SetKwData{Left}{left}
\SetKwData{This}{this}
\SetKwData{Up}{up}
\SetKwFunction{Union}{Union}
\SetKwFunction{FindCompress}{FindCompress}
\SetKwInOut{Input}{Input}\SetKwInOut{Output}{Output}
\SetKwComment{comment}{\#}{}
\Input{data}
\Output{result}
\BlankLine

\textbf{STEP 1:}  Load data \\
\textbf{STEP 2:}  Perform task \\

    \For{$i$ in range (Number of task)}{
        calculate $\Delta$A  = abs( a - b ) \\
        \comment{a is something, b is another thing}
        \If{ $\Delta$A  $\leq$ threshold}
        {do  $\Delta$A  + c  }
   
     }
    
 \caption{simple algorithm}
\end{algorithm}][1]][1]

you should then obtain something like:

Sample Algorithm

For more details do check the documentation, such as :

https://www.ctan.org/pkg/algorithm2e

or

https://www.overleaf.com/learn/latex/Algorithms

You must log in to answer this question.

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