[Tex/LaTex] How to put box around a single equation in align environment

alignbeameremphasisequations

I want to put a box around one of my equations in aligned environment. I am looking to do something similar to Attractive Boxed Equations, but the code only caters for individual equations.

Here is MWE. I want to add box around last equation:

\documentclass{beamer}
\usepackage{amsmath}
\begin{document}
\begin{frame}
  \frametitle {MWE:  Align two set of equations}
    \begin{align*}
      \sigma^2&=(a+b)^2-(a+c)^2 \\
      &=(a^2+b^2-2ab)-(a^2+c^2-2ac)\\
      \intertext{Cancel out common terms, then}
      \sigma^2&= b^2-c^2+2(ac-ab)
    \end{align*}
\end{frame}
\end{document}

enter image description here

Best Answer

You can used the \Aboxed command, from empheq, which can bow a single equation.

I adapted the code to define a \Ashaded and a Acolorboxed command, which use shadecolour, bgcolour and rulecolour parameters, to be defined with \colorlet.

\documentclass[x11names]{beamer}
\usepackage{empheq}

\makeatletter
\colorlet{shadecolour}{Thistle3!50}
\newcommand\Ashaded[1]{\let\bgroup{\romannumeral-`}\@Ashaded#1&&\ENDDNE}
\def\@Ashaded#1&#2&#3\ENDDNE{%
\ifnum0=`{}\fi \setbox \z@
\hbox{$\displaystyle#1{}\m@th$\kern\fboxsep \kern\fboxrule }%
\edef\@tempa {\kern \wd\z@ &\kern -\the\wd\z@ \fboxsep
\the\fboxsep }\@tempa \colorbox{shadecolour}{$#1#2 $}%
}
\colorlet{bgcolour}{LavenderBlush1!50}
\colorlet{rulecolour}{Plum4}
\newcommand\Acolorboxed[1]{\let\bgroup{\romannumeral-`}\@Acolorboxed#1&&\ENDDNE}
\def\@Acolorboxed#1&#2&#3\ENDDNE{%
  \ifnum0=`{}\fi \setbox \z@
    \hbox{$\displaystyle#1{}\m@th$\kern\fboxsep \kern\fboxrule }%
    \edef\@tempa {\kern \wd\z@ &\kern -\the\wd\z@ \fboxsep
        \the\fboxsep\fboxrule \the\fboxrule }\@tempa \fcolorbox{rulecolour}{bgcolour}{$ #1#2 $}%
}
\makeatother

\begin{document}

\begin{frame}
  \frametitle {MWE: Align two set of equations}
    \begin{align*}
      \Acolorboxed{\sigma^2&=(a+b)^2-(a+c)^2} \\
      &=(a^2+b^2-2ab)-(a^2+c^2-2ac)\\
      \intertext{Cancel out common terms, then}
      \Ashaded{\sigma^2&= b^2-c^2+2(ac-ab)}
    \end{align*}
\end{frame}

\end{document}

enter image description here