# 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. Jan 19, 2017 at 13:49
• ok, I misunderstood your question. I thought your picture shown your current result, and not what you're expecting. Jan 19, 2017 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}
\usepackage{trimclip}
\newcommand\boxl{\clipbox{0pt 0pt 1.4\fboxrule{} 0pt}{\fbox{$#1{}$}}}
\newcommand\boxr{\clipbox{1.4\fboxrule{} 0pt 0pt 0pt}{\fbox{${}#1$}}}
\begin{document}
$\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}$
\end{document} • Load amsmath and use \boxed Jan 19, 2017 at 13:59