# How can one prevent \fbox from running off the page?

I am using the \fbox command to box a large chunk of text:

\fbox{Four score and seven years ago our fathers brought forth on this continent, a new nation, conceived in Liberty, and dedicated to the proposition that all men are created equal.}


This text does not line wrap. It just runs off the page. Why does it do that?

-
Usually all \..box macros are designed for smaller pieces of text and place the content into so called restricted horizontal mode where no line breaks or justification is applied. If you want a frame around a larger running text you are using the wrong macro. – Martin Scharrer Jan 27 '12 at 8:23

I think you might be better served using the mdframed package, which handles line breaking and page breaking.

See the MWE below, and the documentation for more elaborate examples

\documentclass{article}

\usepackage{mdframed}

\begin{document}

\begin{mdframed}
Four score and seven years ago our fathers brought forth
on this continent, a new nation, conceived in Liberty, and dedicated to the proposition that all men are created equal.
\end{mdframed}

\end{document}

-

You can use a \parbox for the content as follows:

1. If you do not care about the precise dimensions I just normally use:

\fbox{\parbox{0.90\linewidth}{...}}

2. If you want the text to still occupy the full line width and have the \fbox go into the margins then you can use @Werner's suggestion:

\noindent\makebox[\linewidth][l]{\hspace{\dimexpr-\fboxsep-\fboxrule\relax}\fbox{\parbox{\linewidth}{...}}}

3. If you want the \fbox to stay within the margin boundary you can use:

\noindent\fbox{\parbox{\dimexpr\linewidth-2\fboxsep-\fboxrule\relax}{...}}

Here are the results of these three where I used the [showframe] option to the geometry package to show the margins:

## Code:

\documentclass{article}
\usepackage{xcolor}
\usepackage[showframe]{geometry}

\newcommand{\FboxText}{Four score and seven years ago our fathers brought forth on this continent, a new nation, conceived in Liberty, and dedicated to the proposition that all men are created equal.}

\begin{document}
\fbox{\parbox{0.90\linewidth}{\FboxText}}

\bigskip
\noindent\makebox[\linewidth][l]{\hspace{\dimexpr-\fboxsep-\fboxrule\relax}\fbox{\parbox{\linewidth}{\FboxText}}}

\bigskip
\noindent\fbox{\parbox{\dimexpr\linewidth-2\fboxsep-\fboxrule\relax}{\FboxText}}
\end{document}

-
For an \fbox fitting within the text block, use \noindent\makebox[\linewidth][l]{\hspace{\dimexpr-\fboxsep-\fboxrule\relax}\fbo‌​x{\parbox{\linewidth}{Four ...}}}. – Werner Jan 27 '12 at 4:44
@Werner: Thanks have incorporated that into the answer. – Peter Grill Jan 27 '12 at 17:13
@Werner: mdframed uses \makebox too ;-) – Marco Daniel Jan 27 '12 at 18:27

If you don't want the framed text to break accros pages you can use the adjustbox package for this:

\documentclass{article}

This places the content in a minipage environment with the current line width minus the space needed for the frame. If you want the text to be as wide as the normal text and the frame should go into the margin use \adjustbox{minipage=\linewidth,fbox,center}{..} instead.
You can of course use a suitable minipage inside a \fbox manually if you don't like to load another package, but adjustbox makes live a lot easier. Check out the manual for more useful keys.