LaTeX Framebox and Fbox: Box Text and Equations

November 11, 2026 · 11 min read

LaTeX Framebox, Fbox and Boxed: Put a Box Around Text or Equations

A LaTeX framebox draws a ruled frame around text. Use \fbox{text} to frame text at its natural width, or \framebox[width][position]{text} to set the width and alignment. For equations, use \boxed from amsmath. For colored or titled boxes, use \fcolorbox or the tcolorbox package.

Which LaTeX Box Command Fits What You're Boxing?

Pick the command by what goes inside the frame. A word or short phrase needs \fbox, while a LaTeX framebox suits a label with a fixed width. Equations need \boxed, and theorems or long passages need a package. The last column tells you which commands also work in Markdown math.

What you're boxingCommandPackageRenders in KaTeX
A word or phrase\fbox{...}none (kernel)Yes
Text at a set width or alignment\framebox[4cm][r]{...}none (kernel)No
A paragraph\fbox around a \parboxnone (kernel)No
An equation\boxed{...}amsmathYes
One full line of an align\Aboxed{...}mathtoolsNo
A highlight or colored frame\colorbox, \fcolorboxxcolorYes
A titled or theorem boxtcolorbox environmenttcolorboxNo
A box that crosses a pageframed, mdframed, breakable tcolorboxframed, mdframed, tcolorboxNo

The hollow square at the end of a proof is a symbol, not a frame, so it isn't covered here.

LaTeX Framebox vs Fbox: Width, Alignment and Padding

With no options, \fbox{text} and \framebox{text} do the same thing. Both set the text in a box that can't break or hyphenate, then draw four rules around it with a small gap. The difference is that \framebox takes two optional arguments, a width and a position, as the LaTeX2e reference manual documents.

\fbox{Boxed word}

\framebox[4cm][r]{Flush right}

\framebox[1.5\width]{Extra room}

\framebox[6cm][s]{Spread\hfil out\hfil words}

The first line hugs its text. The second makes a LaTeX framebox 4 cm wide with the text pushed to the right. The position letters are c (centered, the default), l, r and s, which stretches the spaces to fill the width. Inside the width argument, \width means the text's natural width, so 1.5\width adds 50% more room.

Two lengths control the look. \fboxsep is the gap between text and frame, and \fboxrule is the thickness of the rules. The standard article, report and book classes set them to 3pt and 0.4pt. Some references list 0.2pt for the rule, but the class source sets .4pt.

{\setlength{\fboxsep}{6pt}\setlength{\fboxrule}{1pt}\fbox{Thicker frame}}

The outer braces keep the change local, so every other LaTeX box in the document keeps the defaults. Set \fboxsep to 0pt when you frame an image and don't want a white border.

In current LaTeX releases, neither \fbox nor \framebox needs \protect inside a section title or caption, even though some older references still call \framebox fragile. If you only want some sides of the frame, the fbox package on CTAN redefines \fbox to take an optional argument like [lt] for left and top. For decorative frames, the fancybox package adds \shadowbox, \doublebox and \ovalbox.

Boxing Multiple Lines Without Breaking the Margins

Text inside \fbox never wraps, so a long sentence runs straight off the page. Put a \parbox or minipage inside the frame to get a real paragraph:

\noindent\fbox{\parbox{\dimexpr\linewidth-2\fboxsep-2\fboxrule\relax}{%
  A whole paragraph that wraps inside the frame and stays
  within the margins, however long the text gets.}}

That \dimexpr line fixes the most common box complaint: a framed paragraph that sticks out into the right margin. A LaTeX frame box adds \fboxsep and \fboxrule on both sides of whatever sits inside it. With a plain \parbox{\textwidth}, the result is 6.8pt too wide at default settings, which is 2 × 3pt plus 2 × 0.4pt. LaTeX reports it as an overfull hbox. Subtracting the four lengths, as above, puts the outer edge exactly on the margin.

A LaTeX framebox given \linewidth as its width behaves differently. Its width argument already includes the padding and the rules, so the frame comes out at exactly the line width. In our pdfLaTeX test it measured 345pt on a 345pt text block. It still won't wrap text, so keep it for one-line banners.

For a fixed height, use the optional arguments of \parbox: outer position, height and inner position.

\fbox{\parbox[c][3cm][c]{5cm}{\centering Vertically centered}}

The text area is 5 cm wide and 3 cm tall, with the text centered both ways. The frame adds its padding and rules outside that area. A minipage works the same way inside \fbox, and it's easier when the content includes lists or forced line breaks.

To center a boxed line on the page, wrap it in a center environment:

\begin{center}
  \fbox{Centered on its own line}
\end{center}

The center environment adds a little vertical space above and below the box. Inside a figure, use \centering instead, which centers without that extra gap. Our guide to LaTeX text alignment compares the two in more detail.

How Do You Put a Box Around an Equation in LaTeX?

Use \boxed from amsmath. It works like \fbox but sets its contents as display-style math, so fractions and sums keep their full size. That's why it beats \fbox{$...$}, which drops into text-style math and shrinks a fraction to inline size.

\usepackage{amsmath}

\begin{equation}
  \boxed{E = mc^2}
\end{equation}

The identity $\boxed{a^2 + b^2 = c^2}$ also works inline.

The equation number stays outside the frame, at the right margin. Anything boxed in LaTeX with \boxed uses the same \fboxsep and \fboxrule as \fbox, so the grouping trick above changes its padding too. The amsmath user guide documents it in section 4.7.

Aligned equations are trickier. In align, each & splits a line into cells, and \boxed can't reach across them. You have two options:

\usepackage{mathtools} % loads amsmath too

\begin{align}
  \Aboxed{f(x) &= x^2 + 2x + 1} \\
  g(x) &= \boxed{(x + 1)^2}
\end{align}

\Aboxed from mathtools frames the whole first line, alignment point included. The second line boxes only the right-hand side, which needs nothing beyond amsmath. Both lines compile with pdfLaTeX and keep their equation numbers.

Colored Boxes with \colorbox and \fcolorbox

Load xcolor and you get two colored boxes. The LaTeX colorbox command, \colorbox{color}{text}, fills the background behind the text. \fcolorbox{frame}{background}{text} draws a colored rule around a filled box.

\usepackage{xcolor}

\colorbox{yellow}{Highlighted text}
\fcolorbox{red}{white}{Red frame, white fill}
\colorbox{yellow}{$x^2 + y^2 = r^2$}

Both commands take text, not math, so switch to math with dollar signs inside, as the third line does. Padding still comes from \fboxsep, and the frame of \fcolorbox uses \fboxrule. Like a plain LaTeX framebox, they stay on one line, so nest a \parbox for a colored paragraph. Color names and mixes like blue!20 come from xcolor itself. For anything fancier than a highlight, tcolorbox is easier to style.

Theorem Boxes with tcolorbox

For anything bigger than a line, use tcolorbox. It draws framed, colored boxes with optional title bars, and it can turn a theorem environment into a numbered theorem box. The most option loads nearly all of its libraries in one go:

\usepackage[most]{tcolorbox}

\begin{tcolorbox}[title=Key result, colback=yellow!10, colframe=orange!80!black]
  A titled box with a pale fill and a dark orange frame.
\end{tcolorbox}

colback sets the fill, colframe sets the frame and title bar, and title adds the heading strip. For a theorem box that numbers itself, define it once in the preamble with \newtcbtheorem:

\newtcbtheorem{theorem}{Theorem}%
  {colback=blue!5, colframe=blue!60!black, fonttitle=\bfseries}{thm}

\begin{theorem}{Pythagoras}{pyth}
  For a right triangle, $a^2 + b^2 = c^2$.
\end{theorem}

See Theorem~\ref{thm:pyth}.

The four arguments are the environment name, the display name, the box options and a label prefix. Each theorem then takes a title and a marker, and the marker becomes the label thm:pyth. This prints a blue box headed "Theorem 1: Pythagoras". The starred theorem* form gives an unnumbered box, and an optional first argument sets up numbering per section.

We prefer tcolorbox over mdframed for new documents. It's actively maintained, with version 6.10.0 on CTAN since May 2026. One package covers simple frames, theorem boxes and page breaking, and the manual is full of worked examples. The trade-off is weight: it depends on pgf, the graphics engine behind TikZ, so it's a much heavier load than \fbox.

How Do You Make a Framed Box That Breaks Across Pages?

An \fbox is one unbreakable unit. If it doesn't fit in the space left, it jumps to the next page, and if it's taller than a page, it runs off the bottom. To get a LaTeX framed box that splits at a page boundary, use one of three packages.

% framed package
\usepackage{framed}
\begin{framed}
  Long content that may run onto the next page.
\end{framed}

% tcolorbox
\usepackage[most]{tcolorbox}
\begin{tcolorbox}[breakable]
  Long content that may run onto the next page.
\end{tcolorbox}
  • framed by Donald Arseneau gives you framed, shaded and leftbar environments. It's small and stable (version 0.96). The shaded environment needs a color named shadecolor, which you define with \definecolor.
  • mdframed is a separate package that adds colors, titles and keys such as linecolor and linewidth. The version on CTAN, 1.9b, dates from 2013.
  • tcolorbox splits any box once you add the breakable option. The most option already loads that library; otherwise add \tcbuselibrary{breakable}.

For a few framed paragraphs in a report, the framed package is enough. For styled boxes or theorem boxes that cross pages, go straight to tcolorbox.

Which Boxes Render in Markdown Math with KaTeX?

Many Markdown editors and static site generators render math with KaTeX, which supports a subset of LaTeX math. KaTeX renders \boxed, \fbox, \colorbox and \fcolorbox. It doesn't support \framebox, \makebox or \setlength, so a LaTeX framebox with a width argument fails, and \fboxsep can't change. Environments like tcolorbox and framed don't work either, per the KaTeX supported functions list.

Our editor's preview uses KaTeX, so the same rules apply there. If you're new to the dollar-sign delimiters, our guide to writing equations in Markdown covers them. These lines all render:

$$\boxed{E = mc^2}$$

Inline: $\fbox{Remember this}$ in a sentence.

$$\fcolorbox{red}{white}{\textcolor{black}{boxed with a red frame}}$$

In KaTeX, as in LaTeX, \fbox and \colorbox treat their argument as text. Keep plain words inside them, and put math in \boxed instead. A colored box only sets the fill, so on a dark theme the light text stays light. Wrapping the words in \textcolor{black} keeps them readable on a white or yellow fill. Edit the demo below to try your own:

A boxed equation:

E=mc2\boxed{E = mc^2}

An inline box: Remember this\fbox{Remember this} inside a sentence.

key resultx=−b±b2−4ac2a\colorbox{yellow}{\textcolor{black}{key result}} \quad x = \frac{-b \pm \sqrt{b^2-4ac}}{2a}

boxed with a red frame\fcolorbox{red}{white}{\textcolor{black}{boxed with a red frame}}

a2+b2=c2∫01x dx=12\boxed{a^2 + b^2 = c^2} \qquad \boxed{\int_0^1 x \, dx = \frac{1}{2}}

39 words340 characters11 lines
Markdown

The limitation is prose. KaTeX only boxes math, so Markdown has no framed paragraph or titled theorem box. For a boxed note, use a blockquote or a Markdown callout. Real tcolorbox theorem boxes need a full LaTeX build. Markdown vs LaTeX helps you decide when to switch, and our guide to converting Markdown to LaTeX moves your draft over. For one boxed equation as an image, the LaTeX equation editor renders with KaTeX 0.16 and exports PNG or SVG.

Start with \fbox for a word, a LaTeX framebox when you need a set width, \boxed for equations and tcolorbox for theorem boxes or anything that crosses a page. When a frame should fill the line, subtract \fboxsep and \fboxrule from the inner width. To see which boxed equations survive in Markdown, paste them into the editor and watch the KaTeX preview on the right.