[Tex/LaTex] Box around equation in align mode

alignbeamerboxes

I've been trying several different approaches to place a box (a highlight red box) around equations in beamer. Though, I usually do not get the expected result, or a bunch of errors pops up and nothing compiles.

Below follows a MWE of three equations inside the align environment (ideally I want to keep this environment). I need a box that can go at each equation at a time (or more than one sometimes, but not all of them at once). Also, some methods I've tried could not place a box around the \sum correctly, usually cutting part of them out, or the iterators below them.

\documentclass{beamer}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\begin{document}
\begin{align}
   &  \left[ \omega \sum_{k \in K} y_k + \sum_{i \in V} \sum_{j \in V} \sum_{k \in K} c_{ij}x_{ijk}\right]\\
   \notag\\
   & \sum_{k \in K} \sum_{j \in V | j \ne i} x_{ijk} = 1 & & \forall i \in P\\
   \notag\\
   & \sum_{j \in V | j \ne i} x_{ijk} - \sum_{j \in V | j \ne i} x_{dev(i)jk} = 0 && \forall i \in P, k \in K 
\end{align}
\end{document}

Thanks in advance,

Best Answer

I'd recommend the hf-tikz package; it requires hand adjustments, but is completely independent of align.

\documentclass{beamer}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{hf-tikz}

\begin{document}

\begin{frame}
\begin{align}
\tikzmarkin{first}(0.2,0.75)(-0.2,-0.7)
& \biggl[
    \omega \sum_{k \in K} y_k + 
    \sum_{i \in V} \sum_{j \in V} \sum_{k \in K} c_{ij}x_{ijk}
  \biggr]
\tikzmarkend{first}
\\[2ex]
& \sum_{k \in K} \sum_{j \in V | j \ne i} x_{ijk} = 1 
  && \forall i \in P
\\[2ex]
\tikzmarkin{third}(0.2,0.6)(-0.2,-0.75)
& \sum_{j \in V \mid j \ne i} x_{ijk} - \sum_{j \in V \mid j \ne i} x_{dev(i)jk} = 0
  && \forall i \in P, k \in K
\tikzmarkend{third}
\end{align}
\end{frame}

\end{document}

enter image description here

If you just want the red border, with true corners,

\documentclass{beamer}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage[customcolors]{hf-tikz}

\hfsetfillcolor{white}
\hfsetbordercolor{red}

\begin{document}

\begin{frame}
\begin{align}
\tikzmarkin[disable rounded corners=true]{first}(0.2,0.75)(-0.2,-0.7)
& \biggl[
    \omega \sum_{k \in K} y_k + 
    \sum_{i \in V} \sum_{j \in V} \sum_{k \in K} c_{ij}x_{ijk}
  \biggr]
\tikzmarkend{first}
\\[2ex]
& \sum_{k \in K} \sum_{j \in V | j \ne i} x_{ijk} = 1 
  && \forall i \in P
\\[2ex]
\tikzmarkin[disable rounded corners=true]{third}(0.2,0.6)(-0.2,-0.75)
& \sum_{j \in V \mid j \ne i} x_{ijk} - \sum_{j \in V \mid j \ne i} x_{dev(i)jk} = 0
  && \forall i \in P, k \in K
\tikzmarkend{third}
\end{align}
\end{frame}

\end{document}

enter image description here