# Algorithm in oframed environment

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


Is there a way, we can remove the 'Undefined Control Sequence' error, while keeping the frame (because the algorithm is part of a big box containing other texts also, I don't want to remove the box)?

algorithm is one type of float and float always having issue inside \vbox and minipage, you should use the package float and use the option [H] and the modified MWE is:

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

• Thanks a lot! That works. Sep 21 '20 at 7:37
• @Martund Glad to hear.... Sep 21 '20 at 8:42