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)

1
  • Bonus kharma of course
    – denilw
    Commented Jan 13, 2011 at 21:07

3 Answers 3

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?

5
  • Accepted fastest solution. Testing now.
    – denilw
    Commented Jan 13, 2011 at 23:00
  • I think the text's height is the limiting factor for this image when the title is taken into account. I may be wrong, maybe that command doesn't even consider the title.
    – denilw
    Commented Jan 13, 2011 at 23:03
  • width=1\textheight sets the width of the picture to the height of the text.
    – Caramdir
    Commented Jan 13, 2011 at 23:09
  • 1
    @denilw, you should test before accepting...
    – Caramdir
    Commented Jan 13, 2011 at 23:10
  • There is an updated version of this answer at tex.stackexchange.com/a/9561/15107 that is worth looking at. Commented Dec 3, 2017 at 19:46
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

5
  • Some of my code came from your earlier code, which was changed. Grr! ;)
    – frabjous
    Commented Jan 13, 2011 at 22:22
  • But you have an animated gif!
    – Caramdir
    Commented Jan 13, 2011 at 22:25
  • 3
    Yep. Does that get me any bonus points?
    – frabjous
    Commented Jan 13, 2011 at 22:28
  • 1
    I'm very impressed by the animated gif. Bonus kharma and +1 for you.
    – denilw
    Commented Jan 13, 2011 at 23:00
  • Solution works.
    – denilw
    Commented Jan 13, 2011 at 23:52
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}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .