LatexNotes

Boxed equations in LaTeX

\boxed{...} from amsmath draws a frame around maths, the usual way to mark a final answer or a key result.

LaTeX command

\boxed{E = mc^2}

Not the symbol you meant? Draw it to find the command →

Typing up handwritten notes? Convert a whole page of handwriting to LaTeX →

\boxed works inside maths, inline or displayed: \[ \boxed{E = mc^2} \]. In a numbered equation, the box goes around the formula and the number stays outside it. For text rather than maths, \fbox{...} draws the same kind of frame and is built into LaTeX.

To box several lines as one, wrap an aligned block: \boxed{\begin{aligned} a &= b \\ c &= d \end{aligned}}. For a numbered align with a box around all its lines, the empheq package does it in one environment, shown below.

The gap between a box and its contents is \fboxsep and the line's thickness is \fboxrule; set them with \setlength. For colour, \fcolorbox{red}{white}{...} from the xcolor package draws a red frame on a white background; put maths inside it between dollar signs.

A box around a numbered align (empheq)

empheq, which loads mathtools, puts a box around a whole align environment while keeping its equation numbers outside.

\usepackage{empheq}
\begin{empheq}[box=\fbox]{align}
\setlength{\fboxsep}{6pt}

Other forms

\fbox{text}a box around text
\boxed{\begin{aligned} a &= b \\ c &= d \end{aligned}}a box around several lines
\fcolorbox{red}{white}{$x = 1$}a coloured frame, xcolor

Examples

$\boxed{x = 4}$

a boxed answer

$x^2 - 5x + 6 = 0 \implies \boxed{x = 2 \text{ or } x = 3}$

boxing the result of a working

$\boxed{\begin{aligned} a + b &= 5 \\ a - b &= 1 \end{aligned}}$

one box around two aligned lines

$\fcolorbox{red}{white}{$E = mc^2$}$

a coloured frame with xcolor

Tips and common mistakes

Working from handwritten notes?

LatexNotes turns a photo or PDF of handwritten mathematics into LaTeX, graphs and all. It is built with real pdflatex before you see it, and the .tex file is yours to edit or take to Overleaf. Free to try, no sign-up.

See how handwriting to LaTeX works, step by step, or go from GoodNotes to LaTeX if you write on an iPad (Notability works the same way).

Convert your maths to LaTeX →

FAQ

How do I put a box around an equation in LaTeX?

Use \boxed{...} inside maths, for example \[ \boxed{E = mc^2} \]. It needs amsmath.

How do I box several aligned equations?

Put an aligned block inside \boxed, or use the empheq package to box a numbered align.

How do I make a coloured box?

Use \fcolorbox{frame colour}{background colour}{...} from the xcolor package.

How do I box text, not maths?

Use \fbox{...}, which is built into LaTeX.

See also