Framebox in LaTeX: \fbox, \framebox, Empty Boxes and Boxed Text
A frame box in LaTeX is a rectangle drawn around a piece of content. The two kernel commands are \fbox{text}, which fits the frame to its content, and \framebox[width][pos]{text}, which lets you fix the width and align the text inside. Neither needs a package. This guide covers both, the empty boxes and checkboxes used in forms, multi-line boxes with \parbox and minipage, \boxed for equations, colored frames, and the errors you will meet.
Every example was compiled with pdfLaTeX on TeX Live 2025. The whole document below compiles as it is:
\documentclass{article}
\usepackage{amsmath} % \boxed
\usepackage{amssymb} % \square, \boxtimes
\usepackage{xcolor} % \fcolorbox, \colorbox
\begin{document}
A framed word: \fbox{boxed text} sits inline, and math works too: \fbox{$E = mc^2$}.
Fixed width: \framebox[3cm]{centred} \framebox[3cm][l]{left} \framebox[3cm][r]{right}
Blank fields: Name: \framebox[4cm]{\strut} \quad Date: \framebox[3cm]{\strut}
Checkboxes: $\square$ Yes \quad $\square$ No \quad $\boxtimes$ Done
Color: \fcolorbox{red}{yellow}{red frame, yellow fill} \quad \colorbox{yellow}{fill only}
\[ \boxed{x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}} \]
\noindent\fbox{\parbox{\dimexpr\linewidth-2\fboxsep-2\fboxrule\relax}{%
A multi-line box: the \texttt{\string\parbox} wraps the text, and its width is
reduced by the frame so the box ends exactly at the right margin.}}
\end{document}\fbox: The Basic Framed Box
\fbox{...} puts its argument in a horizontal box and draws a rule around it. It is an inline command, so it sits in the line like a word, and anything that fits on one line can go inside, including math in $...$:
A framed word: \fbox{boxed text} sits inline with the sentence.
Math inside: \fbox{$E = mc^2$} and \fbox{$\int_0^1 x^2\,dx = \tfrac13$}.Two lengths control the look. \fboxsep is the padding between the content and the rule, 3pt by default; \fboxrule is the thickness of the rule, 0.4pt by default. Both are ordinary lengths, so you change them with \setlength. Put the change in a group (a pair of braces) and it only applies to the boxes inside that group:
Defaults: \fbox{default frame}
Tighter and thicker, changed locally inside a group:
{\setlength{\fboxsep}{1pt}\setlength{\fboxrule}{1.2pt}\fbox{tight, thick frame}}
No padding at all: {\setlength{\fboxsep}{0pt}\fbox{flush}}
Back to the defaults outside the group: \fbox{default frame}Setting the lengths in the preamble, outside any group, changes every frame in the document, including the ones \fcolorbox and \boxed draw.
\framebox: Fixed Width and Alignment
\framebox[width][pos]{text} is \fbox with two optional arguments. The first is the total width of the box, frame included; the second says where the text sits in it: c centred (the default), l left, r right, or s to stretch the inter-word space so the text fills the box. \makebox takes the same arguments and draws no frame.
Fixed width, centred by default: \framebox[4cm]{centred}
Left aligned: \framebox[4cm][l]{left}
Right aligned: \framebox[4cm][r]{right}
Stretched, the inter-word space grows: \framebox[6cm][s]{one two three}
Same width, no frame: \makebox[4cm][l]{left}The width is the total width: \framebox[4cm]{..} measures exactly 4cm on the page, with the \fboxsep padding and the \fboxrule rule taken out of that 4cm, so \noindent\framebox[\linewidth]{..} fits the line exactly. \fbox works the other way round and adds the frame outside its content, which is what makes the multi-line boxes below overflow. There is also a picture-mode form, \framebox(4,1.5){text}, which measures in \unitlength and is meant for the picture environment; it is rarely what people searching for a frame box want, and it is the cause of one error listed below.
Empty Boxes, Blank Fields and Checkboxes
An empty argument gives you almost nothing: \framebox[2cm]{} compiles, but the box is only 6.8pt tall, padding and rule with no content. To get a blank field the height of a text line, put a \strut inside, or an invisible \rule of the height you want next to a \hspace of the width you want:
Single-line blanks: \framebox[2cm]{\strut} \quad \fbox{\rule{0pt}{1.5em}\hspace{3cm}}
Multi-line answer box, 5cm wide and 3cm tall: \fbox{\parbox[c][3cm][t]{5cm}{\strut}}The \strut in the \parbox matters. We measured \fbox{\parbox[c][3cm][t]{5cm}{}} with a genuinely empty body, and it came out 3cm tall but only 6.8pt wide: an empty paragraph box has no lines, so it collapses to zero width and the frame is a thin vertical bar. Any content, even \strut or ~, restores the full 5cm.
For checkboxes, amssymb provides $\square$ (empty) and $\boxtimes$ (checked). Without a package, \fbox{\phantom{X}} draws a near-square box the size of a capital letter, 14.3pt by 13.6pt in a 10pt document. A typical form row:
\usepackage{amssymb}
\noindent Name: \framebox[6cm]{\strut} \quad Date: \framebox[3cm]{\strut}
\noindent Email: \framebox[\dimexpr\linewidth-1.3cm\relax][l]{\strut}
\noindent Attending? \quad $\square$ Yes \quad $\square$ No \quad $\square$ Maybe
\noindent Text-mode checkbox without amssymb: \fbox{\phantom{X}}
\noindent Comments:\par\vspace{4pt}
\noindent\fbox{\parbox[c][3cm][t]{\dimexpr\linewidth-2\fboxsep-2\fboxrule\relax}{\strut}}These are printed boxes for a form you fill in by hand. Boxes that can be ticked in a PDF viewer are a different mechanism, the Form environment of hyperref.
Multi-Line Boxes: \parbox, minipage and \boxed
\fbox never wraps text. For a framed paragraph put a \parbox inside it, and for anything with lists, displayed equations or footnotes use a minipage. The catch is the width: the frame is added outside the content, so \fbox{\parbox{\linewidth}{...}} is \linewidth plus 2\fboxsep plus 2\fboxrule, which is 6.8pt too wide and pokes into the right margin. Subtract the frame with \dimexpr:
\noindent\fbox{\parbox{\dimexpr\linewidth-2\fboxsep-2\fboxrule\relax}{%
A framed paragraph that wraps to the text width. The width is reduced by
twice \texttt{\string\fboxsep} plus twice \texttt{\string\fboxrule} so the
frame itself ends exactly at the right margin.}}
\bigskip
\noindent\fbox{\begin{minipage}{\dimexpr\linewidth-2\fboxsep-2\fboxrule\relax}
A minipage can hold anything a page can: lists, equations, footnotes.
\begin{itemize}
\item one item
\item another item
\end{itemize}
\[ a^2 + b^2 = c^2 \]
\end{minipage}}In our compile the plain \parbox{\linewidth} version measured 351.8pt against a 345pt line and logged Overfull \hbox (6.79999pt too wide); the \dimexpr version measured exactly 345pt. The \noindent stops the paragraph indent from pushing the box right by another \parindent.
For math, amsmath gives \boxed{...}, which is an \fbox whose content is typeset in display math style. It works in displayed equations, numbered equations and inline:
\usepackage{amsmath}
\[
\boxed{x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}}
\]
\begin{equation}
\boxed{\sum_{k=1}^{n} k = \frac{n(n+1)}{2}}
\end{equation}
Inline: $\boxed{E = mc^2}$.Colored Frames and Backgrounds
With xcolor loaded, \fcolorbox{frame}{background}{text} draws a colored frame over a colored background, and \colorbox{background}{text} fills without a frame. \fcolorbox obeys \fboxsep and \fboxrule; \colorbox has no rule, so only \fboxsep applies. The color names, mixes such as green!60!black and your own \definecolor palettes are covered in the colors guide.
\usepackage{xcolor}
\fcolorbox{red}{yellow}{red frame, yellow background} \quad
\colorbox{yellow}{background only, no frame} \quad
\fcolorbox{blue}{white}{blue frame, white background}
{\setlength{\fboxrule}{2pt}\fcolorbox{green!60!black}{green!10}{thick green frame}}Rounded corners, shadows, titles and boxes that break across pages are beyond \fbox. That is what tcolorbox is for, and the tcolorbox guide goes through its options. The smallest useful example:
\usepackage[most]{tcolorbox}
\begin{tcolorbox}[colback=blue!5, colframe=blue!60!black, title=Note,
arc=3mm, drop shadow]
A rounded box with a title and a shadow.
\end{tcolorbox}A Box Around a Figure, Table or Equation
\fbox frames any box, so wrap it around an \includegraphics or a tabular. Set \fboxsep to 0pt for a frame that touches the image edge. The example uses two \rules as a 5cm by 3cm stand-in so it compiles without an image file:
\usepackage{graphicx}
\usepackage{booktabs}
\begin{figure}[h]
\centering
\fbox{\rule{0pt}{3cm}\rule{5cm}{0pt}} % stand-in for \fbox{\includegraphics[width=5cm]{plot.pdf}}
\caption{A framed figure.}
\end{figure}
\begin{table}[h]
\centering
\fbox{%
\begin{tabular}{lr}
\toprule
Item & Cost \\
\midrule
Paper & 3.00 \\
Ink & 12.50 \\
\bottomrule
\end{tabular}}
\caption{A framed table.}
\end{table}
Tight frame, no padding: {\setlength{\fboxsep}{0pt}\fbox{\rule{3cm}{1cm}}} % same with \includegraphics[width=3cm]{logo.png}For equations use \boxed from the previous section rather than \fbox{$...$}, which would set the math in text style with small fractions and limits.
Common Errors and Surprises
Each of these was reproduced on TeX Live 2025; the log line is quoted as it appears.
| What you see | Cause | Fix |
|---|---|---|
Text after a blank line is pulled onto the same line inside the box, with a large Overfull \hbox in the log | A blank line inside \fbox{...}. There is no error: the box is a single horizontal line, the paragraph break is ignored and the whole text runs on without wrapping. | Put a \parbox or minipage inside the \fbox, as in multi-line boxes. |
Overfull \hbox (6.79999pt too wide) | \fbox{\parbox{\linewidth}...}: the frame is added outside the content width. | Width \dimexpr\linewidth-2\fboxsep-2\fboxrule\relax. |
Runaway argument? then ! File ended while scanning use of \@framepicbox. | \framebox (a) text: when the first character after \framebox is (, LaTeX reads the picture-mode form and looks for (width,height) until the file ends. | Brace the argument: \framebox{(a) text}, which compiles. |
! Undefined control sequence. at \fcolorbox or \colorbox | xcolor (or color) is not loaded. | \usepackage{xcolor} |
! Undefined control sequence. at \boxed | amsmath is not loaded. | \usepackage{amsmath} |
! Missing $ inserted. | A blank line inside \boxed{...}: the paragraph break ends math mode. | Remove the blank line; use aligned or gathered inside \boxed for several rows. |
| A thin vertical bar instead of an answer box | \fbox{\parbox[c][3cm][t]{5cm}{}} with an empty body collapses to zero width. | Put \strut inside the \parbox. |
Frequently Asked Questions
How do I put a box around text in LaTeX?
Use \fbox{your text}. It needs no package, works inline and draws a 0.4pt frame with 3pt of padding. For a fixed width use \framebox[4cm]{text} with an optional l, r or s alignment, and for text that should wrap over several lines put a \parbox or minipage inside the \fbox.
How do I make an empty box in LaTeX?
For a blank single-line field write \framebox[3cm]{\strut}; the \strut gives the box the height of a text line, because an empty argument only produces a flat 6.8pt-high frame. For a multi-line answer box use \fbox{\parbox[c][3cm][t]{5cm}{\strut}}. A completely empty \parbox collapses to zero width, so keep the \strut inside.
How do I make a checkbox in LaTeX?
Load amssymb and write $\square$ for an empty checkbox and $\boxtimes$ for a checked one. Without any package, \fbox{\phantom{X}} draws a near-square text-mode box the size of a capital letter. For clickable boxes in a PDF form you need the hyperref Form environment instead.
What is the difference between \fbox and \framebox?
\fbox{text} fits the frame to its content. \framebox[width][pos]{text} does the same but takes an optional total width, frame included, and an alignment (c by default, l, r or s). With no optional arguments the two are identical. \framebox also has a picture-mode form, \framebox(w,h){text}, chosen whenever the first character after the command is an opening parenthesis.
Why does my \fbox overflow the margin?
The frame is added outside the content, so \fbox{\parbox{\linewidth}{...}} is \linewidth plus 2\fboxsep plus 2\fboxrule, 6.8pt too wide by default, and pdflatex reports an Overfull \hbox. Set the inner width to \dimexpr\linewidth-2\fboxsep-2\fboxrule\relax so the frame ends exactly at the margin.
Next Steps
Frames usually come with one of these:
- Colored Boxes with tcolorbox – Rounded corners, titles, shadows, theorem boxes and boxes that break across pages
- Using Colors in LaTeX – The xcolor names, mixes and custom colors that \fcolorbox and \colorbox take
- Horizontal Lines – \rule, \hrule and the other ways to draw lines without a box
- Tables in LaTeX – Borders around and inside a tabular with booktabs and vertical rules
- Mathematical Expressions – The amsmath environments that go inside \boxed
- Theorems and Proofs – Framed theorem environments with thmtools and tcolorbox
Free LaTeX Tools
- LaTeX Preview – Paste any example above and see the PDF without installing TeX
- LaTeX Symbols Reference – \square, \boxtimes and the other box and shape symbols with copy-paste commands
- LaTeX Templates – Forms, reports and articles with xcolor and amsmath already loaded
Frame it, see it, fix the width in one go
Octree is an AI-powered LaTeX editor with TeX Live already set up: paste any example above, ask for a form with blank fields or a boxed equation, and watch the PDF update as you type, overfull boxes included.
Try Octree Free →