By following the method shown in Background coloring with overlay specification in algorithm2e + beamer package, it is possible to build this MWE:
\documentclass{beamer}
\usepackage{amsmath,amssymb}
\usepackage{tikz}
\usetikzlibrary{fit,calc}
\newcommand{\tikzmark}[1]{%
\tikz[overlay,remember picture,baseline] \node [anchor=base] (#1) {};}
\definecolor{mybrown}{RGB}{255,218,195}
\definecolor{myframe}{RGB}{197,122,195}
\usetheme{Copenhagen}
\begin{document}
\section{Mysection}
\subsection{A subsection}
\begin{frame}{The equations}
\begin{block}{}
\begin{align}
\tikzmark{a}a_i\tikzmark{b} + b_j = 10 & \forall i\in I, j\in J \\
\tikzmark{e}c_j + d_j + \tikzmark{c}a_i\tikzmark{d} >= 30 & \forall i\in I, j\in J\tikzmark{f}
\end{align}
\begin{tikzpicture}[remember picture,overlay]
\coordinate (aa) at ($(a)+(0,0.25)$);
\coordinate (bb) at ($(b)+(0,0)$);
\node<1>[draw=myframe,line width=1pt,fill=mybrown,opacity=0.4,rectangle,rounded corners,fit=(aa) (bb)] {};
\coordinate (cc) at ($(c)+(0,0.25)$);
\coordinate (dd) at ($(d)+(0,0)$);
\node<1>[draw=myframe,line width=1pt,fill=mybrown,opacity=0.4,rectangle,rounded corners,fit=(cc) (dd)] {};
\coordinate (ee) at ($(e)+(0,0.25)$);
\coordinate (ff) at ($(f)+(0,-0.25)$);
\node<2>[draw=myframe,line width=1pt,fill=mybrown,opacity=0.4,rectangle,rounded corners,fit=(ee) (ff)] {};
\end{tikzpicture}
\end{block}
\end{frame}
\end{document}
that allows to get those two frames:
Thus you can select the zone you want to highlight thanks to \tikzmark
, an entire equation or just a part displaying it as "alert"
.
A TikZ-free solution
\documentclass{beamer}
\usepackage{amsmath,amssymb}
\usepackage{xparse}
\usepackage{xcolor}
% Code by Gonzalo Medina
% https://tex.stackexchange.com/questions/35319/a-boxed-alternative-with-minimal-spacing/35346#35346
\newbox\FBox
\NewDocumentCommand\Highlight{O{black}O{white}mO{0.5pt}O{0pt}O{0pt}}{%
\setlength\fboxsep{#4}\sbox\FBox{\fcolorbox{#1}{#2}{#3\rule[-#5]{0pt}{#6}}}\usebox\FBox}
\usetheme{Copenhagen}
\begin{document}
\begin{frame}{The equations}
\only<1>{
\begin{align}
&\Highlight[blue][blue!20]{$a_i$}[3pt] + b_j = 10 \qquad\forall i\in I, j\in J \\
&c_j + d_j +\Highlight[blue][blue!20]{$a_i$}[3pt] >= 30 \qquad \forall i\in I, j\in J
\end{align}
}
\only<2>{
\begin{align}
&a_i + b_j = 10 \qquad \forall i\in I, j\in J \\
&\Highlight[orange][orange!20]{$c_j + d_j +a_i >= 30 \qquad\forall i\in I, j\in J$}[3pt]
\end{align}
}
\end{frame}
\end{document}
Beware that with the latter method, one can not place tabs (with &
) inside the \Highlight
command.
Solution with the hf-tikz
package
\documentclass{beamer}
\usepackage{lmodern,amsmath,amssymb}
\usepackage[beamer]{hf-tikz}
\usetheme{Copenhagen}
\begin{document}
\section{Mysection}
\subsection{A subsection}
\begin{frame}{The equations}
\begin{block}{}
\begin{align}
\tikzmarkin<1>{a}a_i\tikzmarkend{a} + b_j = 10 & \forall i\in I, j\in J \\
\tikzmarkin<2>{c}c_j + d_j + \tikzmarkin<1>{b}a_i\tikzmarkend{b} >= 30 & \forall i\in I, j\in J\tikzmarkend{c}
\end{align}
\end{block}
\end{frame}
\end{document}
Notice that it also avoids the so called "jumping effect" visible in the TikZ-free solution:
Did somebody say text boxes
? Well tcolorbox
is meant for text color boxes
, the 'color' can be set to white, of course. The example below defines a mytextbox
with some preset options, which can be set differently with the optional argument, see the 2nd box example.
\documentclass{article}
\usepackage[margin=2cm]{geometry}
\usepackage[most]{tcolorbox}
\newtcolorbox{mytextbox}[1][]{%
sharp corners,
enhanced,
colback=white,
height=10cm,
attach title to upper,
#1
}
\begin{document}
\begin{mytextbox}
Give some text here:
\end{mytextbox}
\begin{mytextbox}[colupper=blue,fontupper=\bfseries\large]
Give other some text here:
\end{mytextbox}
\end{document}
Best Answer
Another approach, usable with LuaLaTeX. The following sample document was made with the files below.
The TeX input file
and the Lua file (
drawboxes.lua
):