1

I'm making a Beamer presentation and I need space, so I want to hide the inputs and outputs and instead only show my algorithm. But when I simply don't write the input keyword, then the line numbers suddenly disappear:

\documentclass{article}
\usepackage{algorithm2e}
\begin{document}
\begin{algorithm}[H]
    \DontPrintSemicolon
    \LinesNumbered
    \SetKwInOut{Input}{Input} 
    \Input{} % can't omit this, else line numbers don't work ...
    line 1\;
    line 2\;
    line 3\;
    line 4\;
    line 5\;
\end{algorithm}
\end{document}

With \Input:

enter image description here

Without it:

enter image description here

Note: in beamer directly the bug is weirder, as line number show, but are shifted vertically:

enter image description here

1 Answer 1

1

If you add linesnumbered as an option to algorithm2e, it will work.

\documentclass{article}
\usepackage[linesnumbered]{algorithm2e}
\begin{document}
\begin{algorithm}[H]
    \DontPrintSemicolon
    line 1\;
    line 2\;
    line 3\;
    line 4\;
    line 5\;
\end{algorithm}
\end{document}

enter image description here

2
  • Interesting and weird that the global setting behaves differently than the per algorithm \LinesNumbered, but it works. Thank you. I guess you could do that and then where necessary use \LinesNotNumbered. Commented Jan 24, 2018 at 19:39
  • I am not very familiar with the algorithm2e package, but I guess you can use \LinesNotNumbered with the desired result. I don't see clearly why the local setting doesn't work while the global does. Commented Jan 24, 2018 at 19:41

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.