Fonts and Text Formatting

How to Make a Text Box in LaTeX with minipage and parbox

Make a text box in LaTeX with fbox, parbox, and minipage, plus colored boxes with tcolorbox, and choose the right option for short or long text.

On this page
  1. Short answer: fbox for one line, tcolorbox for styled boxes
  2. A simple box with \fbox
  3. Boxes around paragraphs: parbox and minipage
  4. Colored and titled boxes with tcolorbox
  5. Boxing equations
  6. Long text and page breaks
  7. Frequently asked questions

Short answer: fbox for one line, tcolorbox for styled boxes

For a plain box around one line of text, use \fbox. For several paragraphs, a title, or a colored background, use the tcolorbox package. In between, \parbox and minipage handle wrapped paragraphs without extra packages.

\fbox{Boxed text}

A simple box with \fbox

\fbox draws a rectangle around its text. It needs no package, but it does not wrap text: everything stays on one line.

To change the padding and the border thickness, set two lengths before the box:

\setlength{\fboxsep}{6pt}
\setlength{\fboxrule}{1.5pt}
\fbox{Custom padded box}

\fboxsep sets the space between the text and the border, and \fboxrule sets the border’s thickness. Both apply to every later box, so reset them if you need the defaults again.

For a box of a set width, with the text aligned within it, use \framebox:

\framebox[5cm][c]{Centered in a 5 cm box}

Boxes around paragraphs: parbox and minipage

To box several lines, the text has to wrap. Two commands handle that.

A \parbox is a block of text with a fixed width. Put it inside \fbox:

\fbox{\parbox{6cm}{Text that wraps inside a fixed width of 6 cm.}}

A \parbox cannot contain a blank line, because a blank line starts a new paragraph. Use \\ for line breaks instead, or use a minipage.

A minipage is a box that holds full paragraphs, lists, and other environments:

\fbox{
  \begin{minipage}{0.8\textwidth}
    This is a longer paragraph. It wraps to fit the box without running past the margins.

    It can hold a second paragraph too.
  \end{minipage}
}

Colored and titled boxes with tcolorbox

For a callout with a background, a border, or a title, load tcolorbox:

\usepackage{tcolorbox}

Then use its environment:

\begin{tcolorbox}[colback=blue!5!white, colframe=blue!75!black, title=Note]
  This box holds several paragraphs, lists, and equations.
\end{tcolorbox}

The colback option sets the background color, colframe sets the border, and title sets the heading. The color syntax is the same as in xcolor. For colored text and highlights without tcolorbox, see how to change text color in LaTeX with xcolor.

Boxing equations

To box a short expression inside a line of math, put it inside \fbox:

\fbox{$E = mc^2$}

To box a display equation, load amsmath (one of the packages for mathematics in LaTeX) and use \boxed inside the equation environment:

\begin{equation}
  \boxed{a^2 + b^2 = c^2}
\end{equation}

Long text and page breaks

A minipage cannot break across a page, so a long one can be pushed to the next page or run past the bottom of the page. A tcolorbox can split across pages if you add the breakable option:

\begin{tcolorbox}[breakable, title=Long note]
  Text that may run onto the next page.
\end{tcolorbox}

For text aligned to the right inside a box, see right-aligning text in LaTeX.

Frequently asked questions

Why doesn’t my fbox text wrap?

\fbox treats its contents as a single line. Put a \parbox or a minipage inside the box to wrap the text.

What is the difference between parbox and minipage?

A \parbox holds a short block of text with a fixed width, and it cannot contain blank-line paragraph breaks. A minipage holds full paragraphs, lists, and other environments, but it cannot break across pages.

Do I need tcolorbox?

Not for a plain box. Use it when you need colors, a title, or a box that splits across pages.

The complete guide to fonts and text formatting

LaTeX Fonts and Font Families Explained
Read the guide

Keep exploring

Guides from other topics

All topics →