Consider the following
TEXT TEXT TEXT TEXT Figure~\ref{fig:foo} TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT
\begin{figure}
\centering
\includegraphics[width=\textwidth]{foo}
\caption{This is foo.}
\label{fig:foo}
\end{figure}
Now I would like to put a frame around the text and the figure. Ofcourse one could remove the figure
-environment and wrap everything with the fbox
-environment but I need to keep the caption and label (the latter for dynamic referencing):
\fbox{
TEXT TEXT TEXT TEXT Figure~1 TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT
\includegraphics[width=\textwidth]{foo}
}
I tried the following code but it seems not work:
\fbox{
\parbox[c]{\textwidth}{
TEXT TEXT TEXT TEXT Figure~\ref{fig:foo} TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT
}
\begin{figure}
\centering
\includegraphics[width=\textwidth]{foo}
\caption{This is foo.}
\label{fig:foo}
\end{figure}
}
Best Answer
This attempt of yours
won't produce the desired result for two reasons:
You can't use a floating environment (
figure
ortable
or any other user defined floating object) inside a box (in this case, an\fbox
).Blank lines (or equivalently,
\par
commands) inside an\fbox
(or an\hbox
) won't produce an end of paragraph.As others have suggested, you can use the framed package to produce a frame surroundig some material. You cannot use
figure
insideframed
, but that's not a problem: instead, you can use the standard\includegraphics
command (perhaps inside acenter
environment) to include your image and you can give it a caption using the\captionof
command provided either by the capt-of package or by the caption package. A little example:More easily customizable frames can be obtained using the mdframed package.