11

Now I run into a problem with frameboxes. Why is the following not valid LaTeX code?

\framebox{
The following text was taken from:
\begin{quote}
Erik Pickles: How it will end
\end{quote}
}

I get the following error:

something's wrong -- maybe an missing item?

4 Answers 4

12

Framebox doesn't like have an environment inside it. You could consider using the framed package.

\documentclass{article}
\usepackage{framed}
\begin{document}
\begin{framed}
Here is text
\begin{quote}
Here is quote
\end{quote}
\end{framed}
\end{document
1
  • 3
    "Framebox doesn't like have an environment inside it." Isn't correct like that. The issue isn't that quote is an environment but that \framebox forces horizontal mode for its content and quote likes to open a new paragraph and list which doesn't work in that mode. Sep 27, 2011 at 20:55
4

If you do not want to use a package as pointed out by Seamus you can use a minipage to do the trick.

\documentclass[11pt]{article} 
\begin{document}
  \framebox{%
   \begin{minipage}{6cm}
    The following text was taken from:
    \begin{quote}
    Erik Pickles: How it will end
    \end{quote}
   \end{minipage}
  }
\end{document}
3
  • This version has the advantage that the frame box doesn't extend all the way to the end of the frame. It does however have the disadvantage that you have to set the width manually...
    – Seamus
    Nov 30, 2010 at 18:02
  • @Seamus You're right, but you can always adapt to the default version of the command by changing the {6m} to {\textwidth}
    – yannisl
    Nov 30, 2010 at 19:26
  • or you could do some fancy \settowidth magic to get the box to just surround the text you have... I actually think that would be a pretty elegant solution, but I can't work out how to make it into a macro easily...
    – Seamus
    Dec 1, 2010 at 11:22
3

With package varwidth you do not have to know the width of the box

\documentclass[11pt]{article} 
\usepackage{varwidth}
\begin{document}
  \framebox{%
   \begin{varwidth}{\textwidth}% the greatest possible line width
    The following text was taken from:
    \begin{quote}
    Erik Pickles: How it will end
    \end{quote}
   \end{varwidth}%
  }
\end{document}
1

If you don't need to have it break across pages you can use the following.

\documentclass{article} 
\usepackage{adjustbox}
\begin{document}
    \begin{adjustbox}{minipage=\linewidth,fbox}
    The following text was taken from:
    \begin{quote}
    Erik Pickles: How it will end
    \end{quote}
    \end{adjustbox}
\end{document}

Otherwise use framed as Seamus suggested. Herbert's solution to use varwidth is also very good if you have not much text and want a tight frame around it.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .