Home » LaTeX26 May 2015

LaTeX: How to write algorithm?

There are different packages that help writing algorithms on LaTeX. I will be using algorithm2e package for writing algorithm in LaTeX. This package should work fine if you have installed ‘TeX Live Full‘. Otherwise, you may get error while using algorithm2e package. If you get an error then you need to install the package ‘texlive-science‘ which includes algorithm2e package.

On Ubuntu, you can install texlive-science package with the following command:

Here is the complete LaTeX code that has examples on writing algorithm using algorithm2e package. The first algorithm has While loop along with If/Else condition. The second algorithm example has nested ForEach loop with If/ElseIf/Else condition inside it.

Below is the pdf file generated after you compile the above LaTeX source:

Hope this helps.
Thanks.

LaTeX

Get New Post by Email

Find me on

FacebookTwitterGoogle+LinkedInRSS Feed
  • Kamil

    It would be ideal if you could attach also screenshots of result when compiling those examples with library you’re describing.

  • Thanks Kamil for your valuable suggestion. I have added the pdf file generated by the LaTeX source.