113

I want to put a long piece of text in a box, for example

The quick brown fox jumps right over the lazy dog. the quick brown fox 
jumps right over the lazy dog. the quick brown fox jumps right over the lazy 
dog. the quick brown fox jumps right over the lazy dog. the quick brown fox 
jumps right over the lazy dog. the quick brown fox jumps right over the lazy 
dog. the quick brown fox jumps right over the lazy dog. the quick brown fox 
jumps right over the lazy dog.

How can this be done? Any suggestion in brief.

1
103

You can use \fbox{...} to put a frame around a \parbox{...} containing your text. Here's an example document. Note the \noindent that prevents the box from being shifted to the right.

\documentclass{article}

\begin{document}

\noindent\fbox{%
    \parbox{\textwidth}{%
        The quick brown fox jumps right over the lazy dog. the quick brown fox jumps right over the lazy dog. the quick brown fox jumps right over the lazy dog. the quick brown fox jumps right over the lazy dog. the quick brown fox jumps right over the lazy dog. the quick brown fox jumps right over the lazy dog. the quick brown fox jumps right over the lazy dog. the quick brown fox jumps right over the lazy dog.
    }%
}
\end{document}
5
  • 4
    Use \linewidth for two column layout Jan 20 '18 at 2:20
  • If I was to add this to an enumerate, how could I make sure that the box is shifted to the left margin of the page?
    – gen
    Jan 31 '18 at 0:14
  • What do the % symbols do in this? I know it's a comment symbol but it doesn't look like you're commenting anything.
    – Addem
    Jun 9 '19 at 20:31
  • The % are added to prevent the creation of unwanted characters, e.g. linebreaks messing with the spacing around the box.
    – Rayne
    Jun 23 '19 at 15:27
  • Use \linewidth - 2\fboxsep for two column layout and the box around text to align with text.
    – nj2237
    Dec 28 '21 at 14:52
72

A minipage environment is a sufficient way to box or group something:

\documentclass{article}
\begin{document}
\begin{minipage}{15em}
  The quick brown fox jumps right over the lazy dog. the quick brown fox 
  jumps right over the lazy dog. the quick brown fox jumps right over the lazy 
  dog. the quick brown fox jumps right over the lazy dog. the quick brown fox 
  jumps right over the lazy dog. the quick brown fox jumps right over the lazy 
  dog. the quick brown fox jumps right over the lazy dog. the quick brown fox 
  jumps right over the lazy dog.
\end{minipage}
\end{document}

Minipage

If you want to frame it, you can put a \fbox command around it. That is,

\fbox{\begin{minipage}{15em}
...
\end{minipage}}

Minipage + fbox

30

The solutions with \fbox and minipage or \parbox all have the defect that the text will be an indivisible object which can't be split across pages. For a one shot application it might be the way to go. Otherwise there's the mdframed package that's highly customizable.

27

enter image description here

\documentclass{article}
\usepackage{xcolor}
\usepackage{lipsum}
\begin{document}
\lipsum[1]

\medskip

\noindent\fcolorbox{red}{yellow}{%
    \minipage[t]{\dimexpr0.48\linewidth-2\fboxsep-2\fboxrule\relax}
        \lipsum[2]
    \endminipage}\hfill
    \fcolorbox{red}{yellow}{%
    \minipage[t]{\dimexpr0.48\linewidth-2\fboxsep-2\fboxrule\relax}
        \lipsum[3]
    \endminipage}

\medskip

\lipsum[4]
\end{document}

Notes:

  • You can adjust the thickness of border and padding of \fcolorbox{<border-color>}{<background-color>}{<contents>} by setting \fboxrule=<value><unit> and \fboxsep=<value><unit>, respectively. Put the setting before invoking \fcolorbox{<border-color>}{<background-color>}{<contents>}. For example: \fboxrule=1pt and \fboxsep=5pt.
  • Use t, c and b options to align the base line of the most top row, the center row and the most bottom row with the surrounding baseline.
2

If you would like to specify the dimensions of the box (width and height) that is supposed to contain the text, please check this question: Fit text into given box by adjusting the fontsize

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.