[Tex/LaTex] Remove the rule below the algorithm title – using Algorithm2e

algorithm2ecaptions

I'm using algorithm2e package. One of my algorithm does NOT need a title.
If I simply do not type in \caption, there are still three rules.!
I want to remove the second rule.

Is there any way to do this? Thanks!

enter image description here

Best Answer

One could probably detect whether the caption is empty. However, a quick/dirty way is to merely condense the gap (so that the two horizontal rules are drawn overtop of one another). Below two possibilities are presented:

enter image description here

\documentclass{article}
\usepackage[ruled]{algorithm2e}% http://ctan.org/pkg/algorithm2e
\begin{document}

\begin{algorithm}
  \caption{An algorithm}
  aaa\;
  bbb\;
  ccc\;
\end{algorithm}

{
\setlength{\interspacetitleruled}{-.4pt}%
\begin{algorithm}
  aaa\;
  bbb\;
  ccc\;
\end{algorithm}
}

{
\setlength{\interspacetitleruled}{0pt}%
\setlength{\algotitleheightrule}{0pt}%
\begin{algorithm}
  aaa\;
  bbb\;
  ccc\;
\end{algorithm}
}

\end{document}