Frames

The first thing most people type when they want a frame around text in LaTeX is \fbox{...}. It works — right up until the content is longer than one line. Hand it a whole paragraph and the frame refuses to wrap, runs off the edge of the paper, and the log says Overfull \hbox. That single limitation is the reason the framed-box packages — framed, mdframed, tcolorbox — exist at all. This page walks from the built-in \fbox and \framebox up to page-breaking frames and colored, titled panels, held together by one question: why can a frame not be cut in half?

\fbox and \framebox: the built-in frame, and where it stops

\fbox{...} needs no package at all and draws a thin rule fitted snugly around its argument. When you want to dictate width and alignment, reach for \framebox[width][position]{...}: the first optional argument sets the width of the box, the second chooses how the content sits inside it — c (centered, the default), l (flush left), r (flush right), s (stretched to both edges). \framebox with no optional arguments behaves exactly like \fbox. Both are inline boxes that sit on the baseline, so they line up naturally with \hspace and the words around them.

latex
\fbox{a framed word}

% width 5cm, content flush left inside the box
\framebox[5cm][l]{flush left}

% multi-line: frame a \parbox, not the text itself
\fbox{\parbox{0.8\linewidth}{%
  Several lines of text. The inner box wraps them
  first, and only then does the frame go around.}}

And here is the wall. Neither \fbox nor \framebox wraps its content. Give it a long paragraph and it keeps growing rightwards on a single line, pushing the frame off the paper and producing the warning Overfull \hbox (... too wide). This is not a bug but the definition working as written: \fbox assembles its argument into one horizontal box, an \hbox, and an \hbox contains no line-break points at all. To frame several lines, build the paragraph first with \parbox or minipage, as above, and frame that box instead. \parbox and minipage themselves are covered on the “Boxes” page. Even that trick, though, runs out the moment the frame has to cross a page boundary — the reason for which is coming up shortly.

\fboxrule and \fboxsep: thicker rules, roomier padding

Two lengths decide how the frame looks. \fboxrule is the thickness of the rule, 0.4pt by default in the standard classes, and \fboxsep is the padding between the rule and the content, 3pt by default. Both are changed with \setlength. The default 0.4pt is about as fine as the body text, so it is rarely enough when the box is meant to stand out as an admonition. Note, though, that these are ordinary global lengths: change them in the preamble and every \fbox in the document changes with them. To thicken just one box, put the \setlength inside a group {...}, as below. Loading color or xcolor also gives you \fcolorbox{frame}{background}{...}, which obeys the very same two lengths — color names and mixing live on the “Colors (xcolor)” page.

latex
% global: every \fbox in the document becomes thicker
\setlength{\fboxrule}{1pt}
\setlength{\fboxsep}{8pt}

% local: the group limits the change to this one box
{\setlength{\fboxrule}{2pt}\fbox{a heavy frame}}

% same two lengths, plus colour (needs color or xcolor)
\fcolorbox{red}{yellow!20}{warning}

Why a framed box cannot break across a page

The answer is simple: material with a rule drawn around it becomes a single box, and TeX’s page builder can only break between items in a vertical list, never inside a box. The moment you enclose something, it drops out of the list of places the page can be cut. That also reveals what a “breakable frame” really is. No single frame is ever cut in two. The package splits the content into page-sized chunks first, draws a separate frame around each chunk, and stacks them so that the seam is invisible.

Donald Arseneau’s framed package puts that mechanism right on the surface of its design. Its documentation states that the first piece of a split environment gets \FirstFrameCommand, any intermediate pieces get \MidFrameCommand, and the last gets \LastFrameCommand. That is exactly why its oframed environment can leave the frame open at the top and bottom where it breaks: it uses different commands for the ends and the seams, drawing no horizontal rule where the box was cut. The copyright notice in framed.sty runs from 1992, which tells you the problem is older than LaTeX2e itself. And because the mechanism is “split first, decorate after”, the limitations follow naturally: footnotes, floats, and column-spanning material inside a breakable frame are fragile, and the manuals of both tcolorbox and mdframed list that among their caveats.

The framed package: framed, shaded and leftbar

Writing \usepackage{framed} alone gives you three environments that survive a page break. framed draws a rule at the full text width, shaded fills a background instead of drawing a rule, and leftbar draws a single thick vertical rule down the left margin — a common marker for quotations and asides. Anything in the shaded family needs a color named shadecolor to exist first: define it directly with \definecolor{shadecolor}{gray}{0.9}, or load xcolor and write \colorlet{shadecolor}{gray!15}. Forget that and the run stops with an undefined-color error rather than a helpful hint.

latex
\usepackage{framed}
\usepackage{xcolor}
\colorlet{shadecolor}{gray!15}

% these lengths are the framed counterparts of
% \fboxrule and \fboxsep
\setlength{\FrameRule}{1pt}
\setlength{\FrameSep}{10pt}

\begin{framed}
  A long note. If it reaches the bottom of the page the
  frame is split and continues on the next one, which is
  precisely what \fbox cannot do.
\end{framed}

\begin{shaded}
  Filled background instead of a rule.
\end{shaded}

\begin{leftbar}
  A single vertical rule in the left margin.
\end{leftbar}

Dimensions are tuned with \FrameRule and \FrameSep — the package documentation states plainly that these are the lengths used in place of \fboxrule and \fboxsep inside a framed environment. The vertical space before and after the environment is \OuterFrameSep, which defaults to \topsep. A few derived environments come along too: shaded* aligns the edge of the fill to the text width (plain shaded bleeds slightly into the margin), snugshade and snugshade* hug the content tightly, and oframed is the open-at-the-break frame from the previous section. Beyond that, defining your own \FrameCommand and wrapping material in \MakeFramed ... \endMakeFramed lets you build any breakable decoration you like — the documentation calls that the package’s more general purpose. What framed will not give you is rounded corners, shadows, or titles. For those, move up a tier.

Framing an equation with \boxed — which is an \fbox underneath

To box a final result, load \usepackage{amsmath} and use \boxed{...} inside math mode; it typesets the argument as mathematics and then frames it. The interesting part is the definition: inside amsmath, \boxed is written essentially as \fbox{\m@th$\displaystyle#1$}. It is not a separate drawing mechanism at all — it wraps the formula in $...$ and hands it to \fbox. Three practical consequences follow. \fboxrule and \fboxsep apply to it unchanged. It cannot break across a page, naturally. And because \displaystyle is forced, a \boxed written inside a subscript comes out at full size while everything around it shrinks.

latex
\usepackage{amsmath}

\[
  \boxed{E = mc^2}
\]

% \fbox inside math sets its argument in TEXT mode:
% upright roman letters, not math italic
$\fbox{x+y}$ \quad versus \quad $\boxed{x+y}$

Put the two side by side and the difference is obvious. $\fbox{x+y}$ sets its argument in text mode, so both x and y come out upright roman and the spacing around + is not math spacing at all. $\boxed{x+y}$ keeps math italic and math spacing. Inside mathematics, always reach for \boxed. For the more involved requests — enclosing the equation number too, or spanning several lines of an align — the empheq package shipped with mathtools is the right tool. Math mode itself is covered on the “Math mode basics” page.

tcolorbox: color, a title, and breakable

When color, a title and a page break are all wanted at once, tcolorbox is the answer. Load it with \usepackage[most]{tcolorbox} and pass the tcolorbox environment colback= (background color), colframe= (frame color), title= (a title bar) and breakable (allow page breaks). The subtlety that trips people up is what most is for. tcolorbox is split into a core plus a large set of libraries, and breakable is the name of an option and of a library. Write plain \usepackage{tcolorbox}, add breakable, and the box will still refuse to split, because the library was never loaded; you need [most], or an explicit \tcbuselibrary{breakable}. In the source, most expands to many (that is raster, skins, breakable, hooks, theorems, fitting) plus listingsutf8, external, magazine, vignette and poster — everything except minted, which depends on an external tool.

latex
\usepackage[most]{tcolorbox}

\begin{tcolorbox}[colback=blue!5, colframe=blue!60!black,
                  title=Remarks, fonttitle=\bfseries, breakable]
  A coloured box with a title bar. Because breakable was
  given, a long body is split across the page boundary.
\end{tcolorbox}

% inline, fitted to its content, no page breaks
\tcbox[colback=red!5, colframe=red!60!black]{inline box}

The shape is tuned with numeric keys: boxrule= is the rule thickness (default 0.5mm) and arc= the corner radius (default 1mm), with sharp corners for square corners and rounded corners for the curved default. The title bar’s background is colbacktitle= and the heading font is fonttitle= (pass \bfseries or similar). For a single small frame inside a line, use \tcbox{...} rather than the environment — it shrinks to fit like \fbox and, like \fbox, does not break. Underneath it all sits pgf: the core requires pgf, and the skins library included in most requires tikz itself. That is why asking for enhanced puts TikZ’s drawing power directly on show — shadows, double frames, transparency and decorated titles. There is a theorems library for theorem-like boxes, a two-part mode in which \tcblower splits the box so source sits above output, and a great deal more.

“A great deal more” is not a figure of speech. The tcolorbox manual shipped with TeX Live 2024, which texdoc tcolorbox opens, runs to 548 pages — a small monograph, for one package about drawing boxes. Its author is Thomas F. Sturm, who also wrote csvsimple for reading CSV files from LaTeX and genealogytree for typesetting family trees. The practical advice is not to try to read those 548 pages. Four keys — colback, colframe, title, breakable — cover almost everything most documents need; consult the manual’s index when you actually want something fancier.

Reusing one look with \newtcolorbox

Writing the same set of options over and over in the body is something you regret the day you decide to change the color. Define the box once in the preamble with \newtcolorbox. The form is \newtcolorbox[init options]{name}[number of arguments][default]{options}, and like \newenvironment it can create environments that take arguments. If you want a command rather than an environment, use \newtcbox; to shift the defaults for the whole document at once, \tcbset{...}. One habit is worth adopting: name the box for its meaningnote, warning, definition — not for its appearance, as in blueroundbox. Then restyling the whole document later is a few lines in the preamble instead of a search-and-replace through the text.

document.tex
\usepackage[most]{tcolorbox}

% one argument: the heading text
\newtcolorbox{note}[1]{%
  colback=yellow!10, colframe=orange!70!black,
  fonttitle=\bfseries, title=#1, breakable}

\begin{document}
\begin{note}{Careful}
  The note environment is now defined; its heading
  arrives as an argument.
\end{note}
\end{document}

mdframed: the middle ground between framed and tcolorbox

mdframed occupies the space between a frame that looks better than framed and one that costs less than tcolorbox. Load it with \usepackage{mdframed} and pass the mdframed environment optional keys such as backgroundcolor=, roundcorner=, linecolor= and linewidth=. Why the package was written is stated in the author’s own words at the top of its source: working with \fbox or \fcolorbox means handling page breaks by hand, and the mdframed environment deals with them automatically. The very limitation this page started from is thus written down as another package’s reason to exist — and the source says just as plainly that the implementation builds on the idea of framed.sty.

latex
\usepackage{mdframed}

\begin{mdframed}[backgroundcolor=gray!10, roundcorner=5pt,
                 linecolor=gray!60, linewidth=1pt]
  An mdframed box. It breaks across pages.
\end{mdframed}

% a named environment of your own, and a framed theorem
\newmdenv[linecolor=red, linewidth=1.5pt]{alert}
\newmdtheoremenv{prop}{Proposition}

Its distinguishing feature is the choice of drawing backend. framemethod=default uses plain LaTeX commands, while switching to framemethod=TikZ or framemethod=pstricks unlocks fancier decoration. Settings you use often can be gathered into \mdfsetup{...}. Your own framed environment is defined with \newmdenv{...}, and a framed theorem environment with \newmdtheoremenv{...}. One thing worth knowing: the current mdframed is version 1.9b, dated 1 July 2013 — and its source still carries a line saying the package has beta status. It has nevertheless shipped in TeX Live for over a decade and works. For a new document that will be customised heavily, though, the actively maintained tcolorbox is the safer bet.

\fbox or tcolorbox? Choosing between them

There is really only one criterion: the size of the material you want to enclose. A word or a line, \fbox / \framebox. An equation, \boxed. A plain frame around a block of paragraphs, framed. Color and rounded corners, mdframed. A title, page breaks and decoration, tcolorbox. When in doubt, ask first whether the box has to survive a page break — that single question splits the candidates cleanly into two groups. One more piece of practical advice: framed and tcolorbox coexist happily in the same document, but if you care about a consistent look, the result is better when you commit to one of them.

Command / packageWhat it framesBreaks pages?Best for
\fbox / \frameboxContent that fits one lineNoA word or short line, fast
\boxedMathematics, in math modeNoHighlighting a final result
framedBlocks of paragraphsYesA light frame with no decoration
mdframedBlocks of paragraphsYesColor and rounded corners, cheaply
tcolorboxBlocks, inline text, theoremsYes (breakable)Titles, palettes, the full kit