# How do I put a box around a part of a formula?

The question is in the title: How do I put a box around a part of a formula?

Consider the case in which I want to put a box around the second line of the following equation:

$$\begin{split} f(x) &=\sqrt{a^2+x^2}+\\ &+\sqrt{b^2+x^2} \end{split}$$

• try \Aboxed{...} provided by the mathools package. Commented Jan 24, 2019 at 15:43
• If the equation part does not include the & then try boxed{...} provided by amsmath Commented Jan 24, 2019 at 15:47

Here are some options, using \fbox, \boxed and \Aboxed, depending on what you have access to:

\documentclass{article}

\usepackage{mathtools}

\begin{document}

\begin{align*}
f(x) &= \sqrt{a^2 + x^2}  \\
& + \sqrt{b^2 + x^2} \\[2\jot]
f(x) &= \sqrt{a^2 + x^2}  \\
& \fbox{${}+ \sqrt{b^2 + x^2}$} \\[2\jot]
f(x) &= \sqrt{a^2 + x^2}
\hspace{\dimexpr\fboxsep+\fboxrule}
\makebox[0pt][r]{\fbox{\phantom{$f(x) = \sqrt{a^2 + x^2}$}}} \\
& + \sqrt{b^2 + x^2} \\
\Aboxed{f(x) &= \sqrt{a^2 + x^2}} \\
f(x) &= \sqrt{a^2 + x^2} \\
& \boxed{{}+ \sqrt{a^2 + x^2}}
\end{align*}

\end{document}


\Aboxed is able to manage spanning an alignment &. However, you can overprint an \fbox (or \boxed) to achieve the same effect.