Another option, using the tikzmark
library from TikZ; \tikzmark
allows the placement of marks to be used to draw the frame (which can be as fancy as desired):
The code:
\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{tikzmark}
\begin{document}
\begin{tikzpicture}[remember picture,overlay]
\draw
([shift={(-1em,2.5ex)}]pic cs:starta)
rectangle
([shift={(1em,-1.25ex)}]pic cs:enda);
\draw[red!60!black,thick,rounded corners,fill=yellow!30]
([shift={(-1em,2.5ex)}]pic cs:startb)
rectangle
([shift={(1em,-1.25ex)}]pic cs:endb);
\end{tikzpicture}
\begin{align*}
a &= b\\
c &= d\\
\tikzmark{starta}e &= FFF\\
f &= GGG\tikzmark{enda}
\end{align*}
\begin{align*}
a &= b\\
cc &= d\\
\tikzmark{startb}eee &= FFF\\
f &= GGG\tikzmark{endb}
\end{align*}
\end{document}
Since internal calculations are involved, the code needs two runs to stabilize.
In the same spirit, but with shorter code, you can use the hf-tikz
package:
\documentclass{article}
\usepackage{amsmath}
\usepackage{hf-tikz}
\begin{document}
\renewcommand{\fcol}{white}
\renewcommand{\bcol}{black}
\begin{align*}
a &= b\\
c &= d\\
\tikzmarkin{a}(1em,-1.5ex)(-1em,2.5ex)e &= FFF\\
f &= GGG\tikzmarkend{a}
\end{align*}
\renewcommand{\fcol}{yellow!30}
\renewcommand{\bcol}{red!60!black}
\begin{align*}
a &= b\\
cc &= d\\
\tikzmarkin{b}(1em,-1.5ex)(-1em,2.5ex)eee &= FFF\\
f &= GGG\tikzmarkend{b}
\end{align*}
\end{document}
&
fromalign
. BTW: When you use=&
write it as={}&
otherwise the spacing after=
will be wrong. In this case you could just as well use&=
.