[Tex/LaTex] algorithm2e with boxruled gives overfull hbox

algorithm2eboxeswarnings

I am using the algorithm2e package with the boxruled option to format my pseudo-code. However, I am getting an overfull hbox, which I suspect is due to margin/box conflicts.

Does anyone have a fix for this? Minimal working example provided:

\documentclass[11pt]{llncs}

\usepackage[boxruled]{algorithm2e}
\SetAlFnt{\scriptsize}
\SetAlCapFnt{\scriptsize}
\SetAlCapNameFnt{\scriptsize}

\begin{document}
    \begin{algorithm}[H]
    \SetAlgoLined
    \KwData{input}
    \KwResult{output}
    a;
    b;
    c;
    \caption{lalala}
\end{algorithm}
\end{document}

Best Answer

The coding for the boxruled option produces a box that doesn't take into account the width of the rules. This can be corrected as follows, by redefining one internal command:

Sample output

\documentclass[11pt]{article}

\usepackage[boxruled]{algorithm2e}
\SetAlFnt{\scriptsize}
\SetAlCapFnt{\scriptsize}
\SetAlCapNameFnt{\scriptsize}

\makeatletter
\renewcommand{\algocf@caption@boxruled}{%
  \hrule
  \hbox to \hsize{%
    \vrule\hskip-0.4pt
    \vbox{   
       \vskip\interspacetitleboxruled%
       \unhbox\algocf@capbox\hfill
       \vskip\interspacetitleboxruled
       }%
     \hskip-0.4pt\vrule%
   }\nointerlineskip%
}%
\makeatother

\begin{document}
    \begin{algorithm}[H]
    \SetAlgoLined
    \KwData{input}
    \KwResult{output}
    a;
    b;
    c;
    \caption{lalala}
\end{algorithm}

\end{document}

The newcommand differs from that in the style file by (a) printing the horizontal rule first and (b) hiding the widths (0.4pt) of the vertical rules. This essentially how \framebox works, which is what is used for boxing up the body of the algorithm. It can't be used on the caption as one doesn't want to double the dividing rule.