6

When using the algorithm2e package with the beamer class I get a different indentation for the line numberings than when using it with other classes.

With beamer class they look like this: enter image description here

\documentclass{beamer}
\usepackage[ruled,linesnumbered]{algorithm2e}
\begin{document}
    \frame{
        \begin{algorithm}[H]
            \caption{My algorithm}
            \While{something holds}{
                calculate something
            }
            output something
        \end{algorithm}
    }
\end{document}

But I would like to have them like this: enter image description here

\documentclass{article}
\usepackage[ruled,linesnumbered]{algorithm2e}
\begin{document}
        \begin{algorithm}[H]
            \caption{My algorithm}
            \While{something holds}{
                calculate something
            }
            output something
        \end{algorithm}
\end{document}

Any idea would be appreciated. Thank you very much in advance.

Because the problem is so simple I was surprised that after nearly half an hour searching I could not find this question already asked somewhere else. I apologize if this is the case.

1
  • I think this will solve the problem:\IncMargin{1em} \begin{algorithm}
    – M.Ahmadi
    Nov 5, 2019 at 16:57

1 Answer 1

4

Def in algorithm2e:

\IncMargin{length} increases the size of the \algomargin by the length given in argument.

\DecMargin{length} decreases the size of the \algomargin by the length given in argument.

\SetAlCapHSkip{length} sets the horizontal skip before Algorithm: in caption when used in ruled algorithm.

\documentclass{beamer}
\usepackage[ruled,linesnumbered]{algorithm2e}
\begin{document}
    \frame{
    text test!
    \IncMargin{1.5em}
        \begin{algorithm}[H]
        \SetAlCapHSkip{.7em}
            \caption{My algorithm}
            \While{something holds}{
                calculate something
            }
            output something
        \end{algorithm}
        \DecMargin{1.5em}
    text test!
    }
\end{document}

output:

enter image description here

1
  • 3
    Although it looks a little bit like a hack to me (why 1.5em and .7em?) it solves my problem. Thank you very much. Nov 6, 2019 at 14:37

You must log in to answer this question.

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