6

I am using this code to show a pseudocode:

\usepackage{algorithm2e}
...
\begin{algorithm}[H]
\SetAlgoLined
\KwResult{Write here the result }
 initialization\;
 \While{While condition}{
  instructions\;
  \eIf{condition}{
   instructions1\;
   instructions2\;
   }{
   instructions3\;
  }
 }
 \caption{How to write algorithms}
\end{algorithm}

The result is this without any frame around:

enter image description here

If I include \usepackage{algorithm} I get a better result (altho non correct, see while):

enter image description here

But Latex (sharelatex.com) outputs some errors:

/usr/local/texlive/2014/texmf-dist/tex/latex/algorithm2e/algorithm2e.sty, line 2334
LaTeX Error: Command \algorithm already defined.

What could be the problem?

1

1 Answer 1

12

You need to add ruled in the option while loading the package.

enter image description here

Code

 \documentclass{article}

\usepackage[ruled]{algorithm2e}
 \begin{document}

\begin{algorithm}[H]
\SetAlgoLined
\KwResult{Write here the result }
 initialization\;
 \While{While condition}{
  instructions\;
  \eIf{condition}{
   instructions1\;
   instructions2\;
   }{
   instructions3\;
  }
 }
 \caption{How to write algorithms}
\end{algorithm}

\end{document}

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.