You need to redefine the float
environment then if you don't want to change the code of the content. The frame can be added by the mdframed
package (or if you don't need to support page breaks also by my adjustbox
package: \begin{adjustbox}{fbox} <content> \end{adjustbox}
).
\documentclass{article}
%\usepackage{capt-of}% or caption
\usepackage{mdframed}
\let\origfigure\figure
\let\endorigfigure\endfigure
\makeatletter
\newenvironment{figurehere}[1][]{%
\center
\def\@captype{figure}% see note below
}{%
\endcenter%
}
\newcommand{\startfoo}{%
\par\medskip
\begin{mdframed}[linewidth=1pt]%
\let\figure\figurehere
\let\endfigure\endfigurehere
\ignorespaces
}
\newcommand{\stopfoo}{%
\unskip
\end{mdframed}%
\par\medskip
}
\makeatother
\begin{document}
text before text before text before text before
\startfoo
text at begin of framed box
text at begin of framed box
text at begin of framed box
\begin{figure}[h]
some float with a \caption{...}
\end{figure}
text at end of framed box
text at end of framed box
text at end of framed box
\stopfoo
text after text after text after text after text after
\end{document}

Note that is NEVER a good idea to use {figure}[h]
(or [H]
, [h!]
). It is against the float concept. Always use an environment like center
with \captionof
instead.
In this case it is not possible to redefine \caption
like \def\caption{\captionof{figure}}
, because \captionof
is \def\@captype{#1}\caption
and would call itself then. Instead I directly set \@captype
to figure
and so the normal \caption
can be used.
center
or similar environment and use\captionof{figure}{<caption text>}
from thecaption
or (much smaller)capt-of
package, instead of thefigure
environment, as shown in Label and caption without float. – Martin Scharrer♦ Sep 14 '11 at 10:26figure
locally would be an option. – Martin Scharrer♦ Sep 14 '11 at 10:34{}
, but I don't get the caption to work: pastebin.com/d6bYHNzt – topskip Sep 14 '11 at 10:41