36

I have a slide with a figure in it. I want to draw a rounded corner rectangle overtop part of a figure to highlight that section. Bonus points if you can draw two rounded rectangles as overlays that appear one at a time.

alt text

\documentclass{beamer}
\usepackage[T1]{fontenc}

\begin{document}

\begin{frame}
    \frametitle{ESR1} 

    \begin{center}
        Functional analysis
    \end{center}

    \begin{center}
        \includegraphics[width=1\textheight]{some_image.jpg}
    \end{center}
\end{frame}
\end{document}

(Note: I removed most of the unnecessary code in the example code, so the theme in the picture doesn't match with the default one in the example code anymore. --Caramdir)

lockstep
  • 250,273
denilw
  • 3,156

3 Answers3

51

You can include the picture into a TikZ node and then draw some rectangles over it. For example,

\documentclass{beamer}
\usepackage[T1]{fontenc}
\usepackage{tikz}

\begin{document}

\begin{frame}
    \frametitle{ESR1} 

    \begin{center}
        Functional analysis
    \end{center}

    \begin{center}
        \begin{tikzpicture}
            \node[anchor=south west,inner sep=0] at (0,0) {\includegraphics[width=1\textheight]{some_image.jpg}};
            \draw<1>[red,ultra thick,rounded corners] (1.6,1) rectangle (\textheight-1cm,5);
            \draw<2>[red,ultra thick,rounded corners] (5.7,4.1) rectangle (7.5,4.9);
        \end{tikzpicture}
    \end{center}
\end{frame}
\end{document}

with a picture from Wikipedia as some_image.jpg gives the two slides

example

Note the \node[anchor=south west,inner sep=0] at (0,0) {\includegraphics{...}}; line. This adds the picture so that the lower left corner is at the origin of the TikZ coordinate system. Section 14.6 “Rounding Corners” of the TikZ manual (v2.10) tells you how you can change the corner rounding.

Btw, do you really mean width=1\textheight?

Caramdir
  • 89,023
  • 26
  • 255
  • 291
23

Damn you Caramdir, four minutes too late!

Anyway, here's what I came up with. Caramdir's is at least as good, but mine is a bit closer to your syntax, maybe...

\documentclass[english,ignorenonframetext,table]{beamer}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{3}
\usepackage{graphicx}

\makeatletter

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% LyX specific LaTeX commands.
%% A simple dot to overcome graphicx limitations
\newcommand{\lyxdot}{.}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Textclass specific LaTeX commands.
 % this default might be overridden by plain title style
 \newcommand\makebeamertitle{\frame{\maketitle}}%
 \AtBeginDocument{
   \let\origtableofcontents=\tableofcontents
   \def\tableofcontents{\@ifnextchar[{\origtableofcontents}{\gobbletableofcontents}}
   \def\gobbletableofcontents#1{\origtableofcontents}
 }

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands.
\usepackage{xcolor}
\usepackage{listings}
\usetheme{Frankfurt} %Warsaw
\usecolortheme{albatross}
\setbeamercovered{transparent}

\newcommand{\tformating}{
 \definecolor{darkPurple}{rgb}{0.101960784313725,0,0.2}
 \definecolor{purple}{rgb}{0.2,0,0.4}
 \definecolor{lightPurple}{rgb}{0.4,0,0.4}
 \rowcolors[]{1}{darkPurple}{purple}
 \small
}

\usepackage{tikz,overpic}
\usetikzlibrary{fit,shapes.misc}

\makeatother

\usepackage{babel}

\begin{document}
\begin{frame}

\frametitle{ESR1} 

\begin{center}
Functional analysis
\par\end{center}

\begin{center}
\only<1>{\begin{overpic}[width=1\textheight]{some_image.jpg}
\end{overpic}}%
\only<2>{\begin{overpic}[width=1\textheight]{some_image.jpg}
\put(40,38){\tikz \draw[red,thick,rounded corners] (0,0) rectangle (5,1.2);}
\end{overpic}}%
\only<3>{\begin{overpic}[width=1\textheight]{some_image.jpg}
\put(40,38){\tikz \draw[red,thick,rounded corners] (0,0) rectangle (5,1.2);}
\put(0,14){\tikz \draw[red,thick,rounded corners] (0,0) rectangle (3.5,1.2);}
\end{overpic}}%
\par\end{center}

\end{frame}
\end{document}

alt text

frabjous
  • 41,473
11

NOTES

Because I use PSTricks, the image is in eps format. My compilation steps are

  1. latex.exe to convert .tex to .dvi.
  2. dvips.exe to convert .dvi to .ps.
  3. ps2pdf.exe to convert .ps to .pdf.

alt text

\documentclass{beamer}
\usepackage[T1]{fontenc}
\usepackage{pstricks}


\newdimen\ImageW
\ImageW=8cm

\newdimen\ImageH
\ImageH=6cm

\begin{document}

\begin{frame}[t]{ESR1} 

    \begin{center}
        Functional analysis
    \end{center}

    \begin{center}
        \pspicture(\ImageW,\ImageH)
        \rput(0.5\ImageW,0.5\ImageH){\includegraphics[width=\ImageW]{pitfall}}
        %\psgrid%turn on or off for navigational purpose during development
        \pause
        \psset{linecolor=red,linewidth=2pt,framearc=0.5}
        \psframe(5.2,3.8)(6.4,5.6)\pause
        \psframe(2.7,0)(4.5,1)       
        \endpspicture
    \end{center}

\end{frame}
\end{document}
Display Name
  • 46,933