6

Is there any way to add a blank line in algorithm2e?

I have the following document:

\documentclass{article}
\usepackage[linesnumbered]{algorithm2e}% http://ctan.org/pkg/algorithm2e
\begin{document}
\begin{algorithm}
\SetAlgoLined
i = 1 + j\\
% I would like to add a \linebreak here
j = 1 + i\\
\end{algorithm}
\end{document}

This outputs:

enter image description here

I would like to have:

enter image description here

If I add \\ or \linebreak between i = 1 + j\\ and j = 1 + i\\ I get the following error message:

enter image description here

  • 2
    As a workaround you can add \mbox{}\\ or may be easier to type (but less clean) ~\\. – Manuel Jul 20 '14 at 22:53
  • @Manuel Indeed \mbox{}\\ and ~\\ do the trick (I had tried ~`, forgot to add another ` :/). Thanks! – Franck Dernoncourt Jul 20 '14 at 22:54
5

algorithm2e's line-ending macro is \;. From the algorithm2e documentation:

9.1 global code typesetting commands

\; marks the end of a line. Don’t forget it! By default, it prints a ‘;’. You can change this with \DontPrintSemicolon.

enter image description here

\documentclass{article}
\usepackage[linesnumbered]{algorithm2e}% http://ctan.org/pkg/algorithm2e
\DontPrintSemicolon 
\begin{document}
\begin{algorithm}
  $i = 1 + j$\;
  \;
  $j = 1 + i$
\end{algorithm}
\end{document}
| improve this answer | |
14

Instead of the \DontPrintSemicolon trick you should use \BlankLine.

Sample output

\documentclass{article}
\usepackage[linesnumbered]{algorithm2e}% http://ctan.org/pkg/algorithm2e
\DontPrintSemicolon 
\begin{document}
\begin{algorithm}
  $i = 1 + j$\;
  \BlankLine
  $j = 1 + i$
\end{algorithm}
\end{document}
| improve this answer | |
  • 1
    Welcome to TeX.SX! Could you add a screen shot in order to 'prove' that your solution works? – user31729 Feb 22 '15 at 15:49
  • Running you code I get the image added to you post - thus this does not seem to answer the question posed. – Andrew Swann Feb 22 '15 at 15:57
  • Sry. I just read the "blank line" and totaly overlooked that there should be an enumeration at the beginning of the line. So my answer is totaly wrong. Sry for that. – user1660514 Feb 22 '15 at 20:43
  • 3
    Upvoting for \BlankLine since it plays nice with line numbering. – qweruiop Jun 1 '16 at 2:14
  • 1
    This definitely looks better. – lonesome Aug 6 '17 at 3:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.