[Tex/LaTex] Pseudo code algorithm not showing in a frame

algorithm2epseudocode

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?

Best Answer

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}
Related Question