Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
2  
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

3 Answers 3

up vote 11 down vote accepted

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}
share|improve this answer

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:

enter image description here

Note:

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}
share|improve this answer
    
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}
\usepackage{adjustbox}
\begin{document}
\adjustbox{minipage=\linewidth-2\fboxsep-2\fboxrule,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.}
\end{document}

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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