Algorithmus in der `oframed`-Umgebung

Algorithmus in der `oframed`-Umgebung
\usepackage[ruled,vlined]{algorithm2e}
\usepackage{framed}
\setlength\FrameSep{5mm}

\begin{document}
    \begin{oframed} Some text...

                \begin{center}
                \begin{algorithm}
                \DontPrintSemicolon
                \SetKwInOut{Input}{Input}\SetKwInOut{Output}{Output}
                \Input{The input to the algorithm}
                \Output{The output of the algorithm}
                \BlankLine
                \caption{This is what the algorithm does}
                \end{algorithm}
                \end{center}
           Some other text...
    \end{oframed}
\end{document}

Gibt es eine Möglichkeit, den Fehler „Undefinierte Steuersequenz“ zu beheben und gleichzeitig den Rahmen beizubehalten (da der Algorithmus Teil einer großen Box ist, die auch andere Texte enthält, möchte ich die Box nicht entfernen)?

Antwort1

algorithmist ein Typ von floatund floathat immer ein Problem darin \vboxund minipage, Sie sollten das Paket verwenden floatund die Option verwenden [H]und die Änderung MWEist:

\documentclass{book}
\usepackage{float}
\usepackage[ruled,vlined]{algorithm2e}
\usepackage{framed}
\setlength\FrameSep{5mm}

\begin{document}
    \begin{oframed} Some text...

                \begin{center}
                \begin{algorithm}[H]
                \DontPrintSemicolon
                \SetKwInOut{Input}{Input}\SetKwInOut{Output}{Output}
                \Input{$12$ numbered coins, $11$ of which have same weight}
                \Output{Number of the fake coin}
                \BlankLine
                \caption{Finding the fake coin in $3$ measurements}
                \end{algorithm}
                \end{center}
           Some other text...
    \end{oframed}
\end{document}

verwandte Informationen