Algorithm2e style package

Algorithm2e Overview

Algorithm is an environment for writing algorithms. An algorithm is defined as a floating object like figures. It provides macros that allow you to create different sorts of key words, thus a set of predefined key word is given. You can also change the type style of the keywords.

Release 5.2 (see releases section) is the last stable revision published on CTAN, 5.3 is the next candidate release.

Here is an exemple:


Mailing List: You can subscribe to algorithm2e-announce mailing list to receive announcements about revisions of the package and to algorithm2e-discussion to discuss, send comments, ask questions about the package.
 In order to subscribe to the mailing lists you have to send an email to the list manager (see in the documentation the email adresses and how to subscribe).


You can download the postscript "gziped" version

You can download the Pdf version :

And you can download the TeX version :

And the examples required to compile the doc:



Beta 5.3

algorithm2e.sty r5.3 is the beta of the next release. You can try it, if you want. Here are the release notes of this beta

July 25 2017 - revision 5.3

  • Add Option shaded: algorithm text has a background color. You can change it to your own desire by setting algobackground color; e.g. \definecolor{algobackgroup}{gray}{.95} (the default) - note that this option require xcolor package.
  • Add Option titleshaded: algorithm title has a background color. You can change it to your own desire by setting algotitlebackground color; e.g. \definecolor{algotitlebackgroup}{gray}{.95} (the default) - note that this option require xcolor package.
  • Add \setLoaAsLof which set output of list of algorithms as list of figures. This is useful only for classes that redefines output of list of figures and if you want same indentation for the two lists.
  • FIX: SetProgSty changed ArgSty, not ProgSty! This is fixed.
  • FIX: Caption in plain or Tworuled mode was not exactly centered: fixed
  • Change: boxruled and boxed use now \algoheightrule for the thickness of rules
  • Change defaults for \algoheightrule and \algotitleheightrule are now set to \fboxrule

Release 5.2

Algorithm2e r5.2  (07/18/2017) is the last major release since release 5.0. It fix a numerous of bugs from 5.0 and 5.1 that was initially publish in 2015.

Here is an overview of some major add of release 5. For detail on this news, and more information about changes and fixes, please see documentation and release notes.

  • Add: l commands (the ones as \lIf) can now be used with a star. If done, no end of line are done, so you can enclose l command into another one.
  • Add: Now you can have a side comment at end of macros which have a block.
  • Add: new typo styles:
    • Arguments of functions have now their own style. By default, FuncArgSty is the same as ArgSty.
    • Name of KwProg have now their own sty
  • Add: \SetFuncArgSty{}, FuncArgSty{} and SetProgSty{}, ProgSty{} are macros to set and use these new typo styles.
  • Add: Options to manage algorithm hangindent
    •  Option noalgohanging: By default, long statement are indented on subsequent lines; with this option you get old behavior and lines are no more indented
    •  Option hangingcomment: Comment that are alone on a line (not side comment) are not driven by algo hanging: subsequent lines of long comments are indented according to width of start comment marker. With this option, comment are indented like normal statement.
    •  Option hanginginout: As for comment, by default, in/out keywords and input keywords (defined by \SetKwInOut or \SetKwInput) are not indented by algorithm hangindent. They are indented according to width of input keyword. If you want that these keywords acts like normal statement, use this option.
  • Add \SetAlgoHangIndent{length}: This macro allows you to set your own indent length. By default, \SetAlgoHangIndent{0.5em}
  • Add: New group markers macros are \AlgoDisplayGroupMarkers and \AlgoDontDisplayGroupMarkers.
  • Add: \SetCustomAlgoRuledWidth{length} set a custom ruled width of ruled and algoruled options.
  • Add: Block markers. These new macros are:
    • \AlgoDisplayBlockMarkers and \AlgoDontDisplayBlockMarkers
    • \SetAlgoBlockMarkers{begin marker}{end marker}
    • \BlockMarkersSty{text} and \SetBlockMarkersSty
    • Note that a new option has also been added: displayblockmarkers
  • Add: \leIf macro automatically defined by \SetKwIF: allow to define an if-then-else on a single line.
  • Add: new macro \SetStartEndCondition{typo1}{typo2}{typo3} which sets typo around condition in For, If, Switch, Case and Repeat macros.
  • Add: new environment algomathdisplay which allow display math (like inside \[ \] or $$ $$) handling end line and line number
  • Add: new command \SetKwProg{Env}{Title}{is}{end} which defines a macro \Env{args}{text}. Env is a block with 'Title' (in \CapSty) at the beginning followed by args followed by 'is' then 'text' is put below inside a block ended by 'end'. If no 'end' is specified, nothing is written (no blank line is inserted). Useful to typeset function or prog.
  • Add unterminated block: useful to add part separator that doesn't necessary need an end keyword.
  • Add option croatian: croatian keywords (thanks to Ivan Kohan and Yvan Gavran)
  • Add option ngerman: same as german option but so can be used with global option ngerman of babel
  • Add option spanish: Spanish support (thanks to Mario Abarca)
  • Add option turkish: Turkish support

Release 4.01

Release 4.01

See documentation for more information :

Beware! Names of commands have changed to have consistent naming ! If you have old tex files, please use oldcommands option to get back working old named macros.

Please read release notes to learn whats new in this release, and read the documentation to learn how to use all these features.

Summary of changes (see more complete documentation in release notes in algorithm2e.sty)

  • Some commands have been renamed to have consistent naming: option oldcommands enables old naming
  • Compatibily with other packages improven by changing name of internal macros
  • Optionendfloat: This option enables a new environment algoendfloat to be used instead of algorithm; algoendfloat environment put algorithm at the end.
  • Optionrightnl: put lines numbers to the right of the algorithm instead of left.
  • Add: new kind of keywords : KwArray used to define arrays.
  • Add: new macro : \SetKwHangingKw used to define keyword that hangs the text if set on multiple line (so acting as \KwInput)
  • Fix: rules of ruled, algoruled, tworuled styles used rules of different sizes! This is now fixed.
  • Add: size of the rules is now controlled by a length and so can be customized by the user (see lengths algoheightrule and algoheightruledefault and algotitleheightrule and algotitleheightruledefault)
  • Add: \SetAlgoCaptionSeparator which sets the separator between Algorithm 1 and the title.
  • Add: \SetAlgoLongEnd and \SetAlgoShortEnd and \SetAlgoNoEnd commands which act as corresponding package options
  • Option italiano and slovak as new languages
  • Change: Fnt and Sty macro to have consistent use and naming (see below)
  • Add: \AlCapSty, \AlCapNameSty, \AlCapFnt, \AlCapNameFnt, \ProcSty, \ProcFnt, \ProcNameSty, \ProcNameFnt, \ProcArgSty, ProcArgFnt and corresponding "set macro" \SetAlCapSty, \SetAlCapNameSty, \SetAlCapFnt, \SetAlCapNameFnt, \SetProcSty, \SetProcFnt, \SetProcNameSty, \SetProcNameFnt, \SetProcArgSty, \SetProcArgFnt which control the way caption is printed. Sty macro use command taking one parameter as argument, Fnt macros use directly command. All can be redefine (see release for explanation on their difference, how to use them and how to redefine them)
  • Change: \AlTitleFnt to match definition of all other Fnt macros and add a \AlTitleSty macro (see below)
  • Add: \AlTitleSty and \SetAlTitleSty commands to set a style for title.
  • Add: new command \SetAlgorithmName{algorithmname}{list of algorithms name} which redefines name of the algorithms and the sentence list of algorithms.
  • Add: new \SetAlgoRefName{QXY} which change the default ref (number of the algorithm) by the name given in parameter (QXY in the example).
  • Add: new command \SetAlgoRefRelativeSize{-2} which sets the output size of refs, defined by \SetAlgoRefName, used in list of algorithms.
  • Add: two dimensions to control the layout of caption in ruled, algoruled and boxruled algorithms: interspacetitleruled and interspaceboxruled
  • Add:  new feature has been added: the name of the procedure or function set in caption is automatically defined as a KwFunction and so can be used as a macro (beware that macro is only define after the caption)
  • Optionnokwfunc to disable the new feature described above in function and procedure environment.
  • Add: \SetAlgoNlRelativeSize{number} command which sets the relative size of line numbers.
  • Add: \SetAlgoProcName{aname}{aref} command which sets the name of Procedure printed by procedure environment (the environment prints Procedure by default). Second argument is the name that \autoref, from hyperref package, will use.
  • Add: \SetAlgoFuncName{aname}{aref} command which sets the name of Function printed by procedure environment (the environment prints Function by default). Second argument is the name that \autoref, from hyperref package, will use.
  • Add: \SetAlgoCaptionLayout{style} command which sets style of the caption; style must be the name of a macro taking one argument (the text of the caption).
  • Optionprocnumbered: which makes the procedure and function to be numbered as algorithm
  • Optiontworuled and boxruled these are two new layouts: tworuled acts like ruled but doesn't put a line after caption ; boxruled surround algorithm by a box, puts caption above and add a line after caption.
  • Remove  SetKwInParam has been deleted since not useful itself because of different macros which can do the same in a better and a more consistent way as SetKwFunction or SetKw.
  • Fix:  line number is now correctly vertically aligned with math display.
  • Fix:  references with hyperref. No more same identifier or missing name error. BUT now packages if you do PdfLaTeX    you must NOT use naturalnames option of hyperref package.
  • Fix:  autoref with hyperref package.
  • Fix:  titlenumbered was not working! fixed.
  • Fix:  Else(){} acted like uElse. Corrected.
  • Fix:  noend management: when a block was inside another and end of block was following each other, a blank line was added: it's now corrected.
  • Fix:  Function and Procedure environment was no more working as defined originally: the label was no more name of the procedure, it acts always as if procumbered option has been used.
  • Fix:  line numbers had a fixed size which can be bigger than algorithm text accordingly to \AlFnt set (see also new command \SetAlgoNlRelativeSize above)
  • Fix:  semicolon in comments when dontprintsemicolon is used.
  • Fix:  listofalgorithms adds a vertical space before first algo of a chapter as for listoffigures or listoftables
  • Fix:  listofalgorithms with twocolumns mode and some classes which don't allow onecolumn and so don't define \if@restonecol as prescribed in LaTeX (sig-alternate for example)
  • Fix:  algorithm2e now works with elsart cls and some more classes.
  • Fix:  blocks defined by SetKwBlock act now as other blocks (if for instance) and don't write end in vlined mode, instead they print a small horizontal line as required by the option.
  • Fix:  underfull hbox warning at each end of algorithm environment removed.

Release 3.9

: (10/04/2005) corrects references bug with hyperref packages, fix compatibility with caption package, improve compatibility with beamer and add:

  • side comments which allows to put comments to the right of the text and on the same line.
  • possibility to add side comment on the same line of a block command like if-then-else by using () before the {} block.
  • add SetAlgoInsideSkip to put extra vertical space inside the environment around the core of the algorithm.
  • dotocloa option which adds an entry in the toc for the list of algorithms.

Release 3.6

: corrects bugs of vertical spacing with some macros, improve compatibility with some classes (IEEEtran, Beamer and Hermes) and add 3 new features:

  • hidden numbering: lines can be auto-numbering but showing numbers only on lines you specify.
  • managing of caption font: now caption can have a different font from the algorithm
  • managing distance between caption and algorithm in boxed and plain mode.

Old releases

LaTeX 2e :

Documentation :

Dernière mise à jour le 25/07/2017