1

I want to draw a text-width frame/box around a paragraph of text, like thisenter image description here

I used framed environment from framed package

\documentclass{article}
\usepackage{framed}
\begin{document}
    \textbf{Problem} blah, blah, ...
    \begin{framed}
        \textbf{Answer} blah blah, ...

        blah blah blah blah blah blah blah blah blah

        ...
    \end{framed}
\end{document}

But I cannot use figure, algorithm environments in this framed environment. Any solutions?

6
  • Did you try a simple \begin{center}\includegraphics{foo}\\ \captionof{figure}{Foo caption}\end{center}?
    – Bernard
    Sep 30, 2017 at 10:23
  • @Bernard's suggestion would require \usepackage{caption}. (And the \\ is not necessary, I believe.) Sep 30, 2017 at 10:37
  • @TorbjørnT. You're right, it's not necessary.
    – Bernard
    Sep 30, 2017 at 11:55
  • @Bernard Thanks, but how about subfigures and algorithms? I can only use algorithmic environment without algorithm. Sep 30, 2017 at 12:11
  • There should be no problem for subfigures: you can use \captionof{subfigure}{...}. Also, you can load the float package and the [H]` placement option for figure/algorithm.
    – Bernard
    Sep 30, 2017 at 12:26

1 Answer 1

1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.