# Beamer - Make Overlaid tikzpicture Disappear

Say that I have a frame in Beamer like this (where I load the table from an external file):

\begin{frame}
\frametitle{Table Name}
\begin{table}[htbp]
\begin{tabular}{c | cccc}
\input{\dir/table}

\pause \begin{tikzpicture}[overlay]
\draw[red,ultra thick,rounded corners] (2.5,1.3) rectangle (3.4,4.2);
\end{tikzpicture}

\pause \begin{tikzpicture}[overlay]
\draw[red,ultra thick,rounded corners] (1.5,1.3) rectangle (2.4,4.2);
\end{tikzpicture}

\end{tabular}
\end{table}
\end{frame}


My goal is to highlight two different areas of the table with the overlaid tikzpicture's. I don't want the first highlight (or second) to appear until I advance the slide. When I advance it, I only want the first to appear and not the second. When I advance it again, I only want the second to appear, and not the first. The \pause command gets me a lot of mileage, and I think the main issue is having the first highlight disappear when I am on the last slide and only want the second highlight.

Does the answer have to do with?: \setbeamercovered{transparent}

and

As requested, a MWE:

\documentclass[compress]{beamer}
\usepackage{tikz}
\begin{document}

\begin{frame}
\frametitle{Table Name}
\begin{table}[htbp]
\begin{tabular}{c | cccc}
A          &       B&        C&   D\\
\hline
1                   &        1&       6&       7\\
2                   &         2&       5&       8\\
Total               &        3&      4&        9    \\

\pause \begin{tikzpicture}[overlay]
\draw[red,ultra thick,rounded corners] (1,1) rectangle (2,2);
\end{tikzpicture}

\pause \begin{tikzpicture}[overlay]
\draw[red,ultra thick,rounded corners] (1,3) rectangle (2,4);
\end{tikzpicture}

\end{tabular}
\end{table}
\end{frame}

\end{document}


TikZ drawing macros are overlay-aware, so you can do something like the example below. \draw<2> .. means that \draw is only shown on the second slide.

Note that in your example the table environment is not really necessary. In a beamer presentation, it's only needed if you want to have a \caption. And for that matter, since a table is not a float in beamer (that wouldn't make sense), the float placement options ([htpb]) doesn't do anything.

\documentclass[compress]{beamer}
\usepackage{tikz}
\begin{document}

\begin{frame}
\frametitle{Table Name}
\begin{tabular}{c | cccc}
A          &       B&        C&   D\\
\hline
1                   &        1&       6&       7\\
2                   &         2&       5&       8\\
Total               &        3&      4&        9
\begin{tikzpicture}[overlay]
\draw<2>[red,ultra thick,rounded corners] (1,1) rectangle (2,2);
\draw<3>[red,ultra thick,rounded corners] (1,3) rectangle (2,4);
\end{tikzpicture}
\end{tabular}
\end{frame}
\end{document}


You might be interested in the tikzmark library though. The \tikzmark{<name>} macro allows you to make a marker in the table (or any other text). You can use that as a coordinate with (pic cs:<name>). Note that the tikzpicture needs the options [remember picture,overlay].

\documentclass[compress]{beamer}
\usepackage{tikz}
\usetikzlibrary{tikzmark}
\begin{document}

\begin{frame}
\frametitle{Table Name}
\begin{tabular}{c | cccc}
A                   &   \tikzmark{a}B&      C&   D\\
\hline
1                   &     1&    6\tikzmark{b}&       7\\
2                   &     2&      \tikzmark{c}5&       8\\
Total               &     3&      4&        9\tikzmark{d}
\end{tabular}
\begin{tikzpicture}[overlay,remember picture]
\draw<2>[red,ultra thick,rounded corners] ([shift={(-2pt,12pt)}]pic cs:a) rectangle ([shift={(2pt,-2pt)}]pic cs:b);
\draw<2>[red,ultra thick,rounded corners] ([shift={(-2pt,12pt)}]pic cs:c) rectangle ([shift={(2pt,-2pt)}]pic cs:d);
\end{tikzpicture}
\end{frame}
\end{document}

• Is it possible to draw the same tikzpicture outside of the tabular environment? – bill999 Oct 1 '17 at 3:16
• @bill999 Yes. Just move it outside. I added an addendum to my answer by the way. – Torbjørn T. Oct 1 '17 at 7:43