The float environments like figure
, table
others can't be placed inside other environments or boxes as they really float through the text and are placed when the TeX engine finds a good place to put them. They are not part of their surrounding code.
So if you want something framed and floating, you need to put the framing code/environment into the floating environment.
Simple example:
\documentclass{article}
\usepackage{framed}
\usepackage{lipsum} % for example text filler only
\begin{document}
\lipsum
\begin{figure}
\textbf{Problem} blah, blah, ...
\begin{framed}
\textbf{Answer} blah blah, ...
blah blah blah blah blah blah blah blah blah
...
\end{framed}
\end{figure}
\lipsum
\end{document}
However, if you want the content of a normally floating environment on a specific spot you should not use that environment, but a non-floating replacement which gives you the same features like caption etc. without the floating effect. If so, see e.g. the nofloat
key of the adjustbox
package.
\begin{center}\includegraphics{foo}\\ \captionof{figure}{Foo caption}\end{center}
?\usepackage{caption}
. (And the\\
is not necessary, I believe.)algorithmic
environment withoutalgorithm
.\captionof{subfigure}{...}
. Also, you can load thefloat
package and the [H]` placement option for figure/algorithm.