# algorithm2e options algonl and boxed seem to clash

I'm using a solution suggested by C. Fiorio in Want Knuth style line numbering in algorithm2e algorithms. The suggestion was to use the algonl option for algorithm2e to achieve Knuth style algorithm line numbering; i.e. Algorithm #3 should have lines numbered 3.1, 3.2, 3.3, etc. However it seems the line number overflow the bounding box if I use the boxed option.

Can someone suggest a good way to fix this so that the algorithm box does not clash with the line numbering?

Here is what I see rendered. Here is a minimum working example.

\documentclass{article}

\usepackage[noend,boxed,linesnumbered,algonl]{algorithm2e}
\SetKwProg{Fn}{Function}{}{end}

\begin{document}

\begin{algorithm}[H]\label{algo.find.augmenting.path}
\caption{Implementation of function to find an augmenting path if one exists.}
\DontPrintSemicolon
\Fn{find-augmenting-path-or-none$(adj,E,M)$}{
\SetKwInOut{Input}{Input}\SetKwInOut{Output}{Output}
\Input{$adj$ adjacency list of simple graph}
\Input{$E$ set of edges}
\Input{$M$ a matching}
\BlankLine
$free \gets$ generate-free-vertices() \;
\If{$|free| < 2$}{
\Return None \;
}
\tcp*[l]{Find set of length=2 paths starting at a free vertex}
$paths \gets \{[u,v] \mid u\in free, \{u,v\} \in E \}$\label{algo.line.paths.1b}\;
$k \gets 1$  \tcp*{index of 2nd element of 0-index-based array}
\While{$paths \neq \emptyset$}{
\If{odd$(k)$}{
\For{$p \in paths$}{
\If{ $p_k \in free$ }{
\Return p\;
}
}
}
$paths \gets$ extend-alternating-path$(adj,M,k,free,paths)$ \;
$k \gets k+1$ \;
}
\Return None
}
\end{algorithm}

\end{document}


Setting a larger \algomargin solves the problem. You can

• directly set \setlength\algomargin{3em} or
• use \IncMargin{<length>} to add <length> to \algomargin.

See the documentation of algorithm2e, sec. 9.6.

Alternatively, you can

Full example

\documentclass{article}

\usepackage[noend,boxed,linesnumbered,algonl]{algorithm2e}
\SetKwProg{Fn}{Function}{}{end}

\setlength\algomargin{3em}

\begin{document}

\begin{algorithm}[H]\label{algo.find.augmenting.path}
\caption{Implementation of function to find an augmenting path if one exists.}
\DontPrintSemicolon
\Fn{find-augmenting-path-or-none$(adj,E,M)$}{
\SetKwInOut{Input}{Input}\SetKwInOut{Output}{Output}
\Input{$adj$ adjacency list of simple graph}
\Input{$E$ set of edges}
\Input{$M$ a matching}
\BlankLine
$free \gets$ generate-free-vertices() \;
\If{$|free| < 2$}{
\Return None \;
}
\tcp*[l]{Find set of length=2 paths starting at a free vertex}
$paths \gets \{[u,v] \mid u\in free, \{u,v\} \in E \}$\label{algo.line.paths.1b}\;
$k \gets 1$  \tcp*{index of 2nd element of 0-index-based array}
\While{$paths \neq \emptyset$}{
\If{odd$(k)$}{
\For{$p \in paths$}{
\If{ $p_k \in free$ }{
\Return p\;
}
}
}
$paths \gets$ extend-alternating-path$(adj,M,k,free,paths)$ \;
$k \gets k+1$ \;
}
\Return None
}
\end{algorithm}

\end{document} • Thanks muzimuzhi Z, that works well. Mar 25, 2020 at 12:37
• @JimNewton If you like the proposed answer and it was helpful, please consider upvoting (by clicking on the arrows next to the score) and/or marking it as the accepted answer (by clicking on the checkmark ✓). Mar 25, 2020 at 17:51
• @BambOo, thanks for the suggestion. I had upvoted it, but forgot to click the checkmark. Thanks for the kind reminder. Mar 26, 2020 at 7:16