“oframed”環境中的演算法

“oframed”環境中的演算法
\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}

有沒有辦法,我們可以刪除“未定義的控制序列”錯誤,同時保留框架(因為該演算法是還包含其他文字的大框的一部分,我不想刪除該框)?

答案1

algorithm是一種類型float並且總是在andfloat內部存在問題,您應該使用該套件並使用該選項,修改後的內容是:\vboxminipagefloat[H]MWE

\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}

相關內容