\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
,并且总是在和float
内部出现问题,您应该使用该包并使用该选项,修改后的是:\vbox
minipage
float
[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}