5

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}

2 Answers 2

4

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.

1
  • Are you a friend of Marcel Proust? :-)
    – jjstcool
    Commented May 9, 2017 at 21:17
0

I had the same issue as mentioned in the question, but the answer given by Andrew did not work on a mch larger document I had. Maybe I had other packages in my preamble that prevented the idea Andrew had. It will take me a few days just to figure out which package caused it, but in the mean time I can give a easier solution that help me when I had a problems with margins and my old printer.

Just after loading the document class, article in my case I needed to improved the margins of my document since the printer was always off by a bit. [The single command of \usepackage[4apaper]{geometry) was not doing it by itself.] I added some corrections and it did help erase the issue of `Overfull \hbox (17.0pt too wide) detected at line' at the end of my algorithm call.

The snippet is only to offset the margins enough for my printer to work.

\hoffset -0.0625in 
\voffset 0.15625in
\parindent0em

If I find which package cause Andrew's answer not to work, I will come back here and add it as a comment.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .