# How to do a box around equation

I need to do this box . How can I do that?

• I tried but result is box around whole equation, not like in the picture. – Blichar Jan 19 '17 at 13:49
• ok, I misunderstood your question. I thought your picture shown your current result, and not what you're expecting. – ebosi Jan 19 '17 at 13:51

Hackjob to get

First I print a boxed equation with horizontal space equivalent of the root, then print the root in box with white background on top.

\documentclass{article}
\usepackage{amsmath}
\usepackage{xcolor}
\begin{document}
\fboxsep=1pt\relax \newcommand\MyRoot{{}= \sqrt{\frac{4\pi\delta}{\sigma_1\bigl((X+Y)(X-Y)\bigr)^{\sigma_2}}}} \ooalign{% \displaystyle\boxed{\hat{g} \hphantom{\displaystyle\MyRoot} \approx 999.121}\cr \fboxsep=0pt\relax\hspace{0.8em}\colorbox{white}{\displaystyle\MyRoot} }
\end{document}


egreg suggests using \boxed macro of the amsmath package.

\documentclass{article}
\usepackage{amsmath}
\begin{document}
$\fboxsep=1pt\relax \boxed{\hat g} = \sqrt{\frac{4\pi\delta}{\sigma_1\bigl((X+Y)(X-Y)\bigr)^{\sigma_2}}} \boxed{{}\approx 999.121}$
\end{document}


Without any packages, (i.e., with \fbox):

\documentclass{article}
\begin{document}
$\fboxsep=1pt\relax \fbox{\hat g} = \sqrt{\frac{4\pi\delta}{\sigma_1\bigl((X+Y)(X-Y)\bigr)^{\sigma_2}}} \fbox{{}\approx 999.121}$
\end{document}


I did not originally perceive the 3-sided nature of the applied boxes in the OP's figure. That can be achieved using the current method, with the addition of a \clipbox upon the \fbox. It has been macroed as \boxl{} and \boxr{}:
\documentclass{article}
\newcommand\boxl[1]{\clipbox{0pt 0pt 1.4\fboxrule{} 0pt}{\fbox{$#1{}$}}}
\newcommand\boxr[1]{\clipbox{1.4\fboxrule{} 0pt 0pt 0pt}{\fbox{${}#1$}}}
$\fboxsep=1pt\relax \boxl{\hat g} = \sqrt{\frac{4\pi\delta}{\sigma_1\bigl((X+Y)(X-Y)\bigr)^{\sigma_2}}} \boxr{\approx 999.121}$

• Load amsmath and use \boxed – egreg Jan 19 '17 at 13:59