# Example: Beamer arrows

Published 2006-11-09 | Author: Kjell Magne Fauske

With PGF/TikZ version 1.09 and later, it is possible to draw paths between nodes across different pictures. This is a useful feature for presentations with the Beamer package. In this example I've combined the new PGF/TikZ's overlay feature with Beamer overlays. Download the PDF version to see the result.

Note. This only works with PDFTeX, and you have to run PDFTeX twice.

Author: Kjell Magne Fauske

Do you have a question regarding this example, TikZ or LaTeX in general? Just ask in the LaTeX Forum.
Oder frag auf Deutsch auf TeXwelt.de.

\documentclass{beamer} %
\usetheme{CambridgeUS}
\usepackage[latin1]{inputenc}
\usefonttheme{professionalfonts}
\usepackage{times}
\usepackage{tikz}
\usepackage{amsmath}
\usepackage{verbatim}
\usetikzlibrary{arrows,shapes}

\author{Author}
\title{Presentation title}

\begin{document}
% For every picture that defines or uses external nodes, you'll have to
% apply the 'remember picture' style. To avoid some typing, we'll apply
% the style to all pictures.
\tikzstyle{every picture}+=[remember picture]

% By default all math in TikZ nodes are set in inline mode. Change this to
% displaystyle so that we don't get small fractions.
\everymath{\displaystyle}

\begin{frame}
\frametitle{Rigid body dynamics}

\tikzstyle{na} = [baseline=-.5ex]

\item Coriolis acceleration
\tikz[na] \node[coordinate] (n1) {};
\end{itemize}

% Below we mix an ordinary equation with TikZ nodes. Note that we have to
% adjust the baseline of the nodes to get proper alignment with the rest of
% the equation.
\begin{equation*}
\vec{a}_p = \vec{a}_o+\frac{{}^bd^2}{dt^2}\vec{r} +
\tikz[baseline]{
\node[fill=blue!20,anchor=base] (t1)
{$2\vec{\omega}_{ib}\times\frac{{}^bd}{dt}\vec{r}$};
} +
\tikz[baseline]{
\node[fill=red!20, ellipse,anchor=base] (t2)
{$\vec{\alpha}_{ib}\times\vec{r}$};
} +
\tikz[baseline]{
\node[fill=green!20,anchor=base] (t3)
{$\vec{\omega}_{ib}\times(\vec{\omega}_{ib}\times\vec{r})$};
}
\end{equation*}

\item Transversal acceleration
\tikz[na]\node [coordinate] (n2) {};
\item Centripetal acceleration
\tikz[na]\node [coordinate] (n3) {};
\end{itemize}

% Now it's time to draw some edges between the global nodes. Note that we
% have to apply the 'overlay' style.
\begin{tikzpicture}[overlay]
\path[->]<1-> (n1) edge [bend left] (t1);
\path[->]<2-> (n2) edge [bend right] (t2);
\path[->]<3-> (n3) edge [out=0, in=-90] (t3);
\end{tikzpicture}
\end{frame}
\end{document}


• #1 Markus, July 3, 2009 at 1:40 p.m.

Note. This only works with PDFTeX, and you have to run PDFTeX twice.

No, you don't. TikZ provides serveral backend drivers. You may also use latex → dvips for the example code.

• #2 Kjell Magne Fauske, July 3, 2009 at 2:07 p.m.

You are right Markus, but when the example was written it only worked with pdftex. I don't remember when it started to work with other backends.

• #3 K S Mallesh, August 27, 2009 at 7:16 p.m.

Hello, This is quite impressive. I wish to learn it soon. Thanks for being so helpful

I wish to show one animation that shows step by step the 6 degrees of freedom of a rigid body. Three non-collinear point masses labelled m1,m2,m3 should move in the following way in space.

1) m1 can move in any way it likes- 3 degrees of freedom

2) m2 can move on the surface of a sphere of constant radius with m1 as centre.- 2 degrees of freedom

3) m3 has to move on the circumference of a circle such that the line joining m1 and m2 is perpendicular to the plane of the circle and the line passes through the centre of the circle.- 1 degree of freedom.

This will be a good animation. Can you help?

With regards Mallesh

• #4 Kjell Magne Fauske, August 27, 2009 at 8:52 p.m.

@Mallesh: Sounds like a fun project, but I don't think Beamer and/or TikZ is the right tool for such a task. TikZ's 3D-support is quite basic. I recommend taking a look at Asymptote or Blender

• #5 Nasimul Haque, October 13, 2009 at 2:23 p.m.

Hi,

I am trying this on my white MacBook. I have MacTeX 2008 installed and pgf/tikz installed in my home library texmf folder. Compiling I get following errors:

Latex Error: ./beamer-arrows.tex:85 Incompatible list can't be unboxed.

Latex Error: ./beamer-arrows.tex:85 Output routine didn't use all of \box255.

Latex Error: ./beamer-arrows.tex:85 Incompatible list can't be unboxed.

Latex Error: ./beamer-arrows.tex:85 Output routine didn't use all of \box255.

• #6 Kjell Magne Fauske, October 14, 2009 at 9:09 a.m.

@Nasimul: Try inserting \RequirePackage{atbegshi} at the start of your document:

\RequirePackage{atbegshi}
\documentclass{beamer}
\begin{document}
...


Apparently there is an incompatability between Beamer/PGF and hyperref.

• #7 Tom Price, October 22, 2009 at 3:39 a.m.

Kjell,

Is possible to color the complement of the rectangle or ellipse to create something like a spotlight? If so, is it possible to color the complement using a gradient fill with the fill color becoming more prominent as your view moves away from the rectangle or ellipse?

Once again, I wish to thank you for your many helpful examples.

Tom

• #8 Kjell Magne Fauske, October 22, 2009 at 9:36 a.m.

@Tom Price: You want an effect similar to the one in the example Transparent PNG overlay?

Using a transparent PNG like in the PNG overlay example is probably the easiest approach to the problem. You can create one using for instance Gimp, Inkscape or Photoshop.

PGF does support gradient transparency fills. They are called shadings. You can read more about them in Chapter 20 in the manual (CVS version). You can probably achieve the effect you want using shadings, but keep in mind that shadings are not supported well by all PDF viewers.

• #9 Kjell Magne Fauske, October 22, 2009 at 10:43 a.m.

Here is a basic example using fadings:

\RequirePackage{atbegshi}
\documentclass{beamer} %
\usetheme{CambridgeUS}
\usepackage[latin1]{inputenc}
\usefonttheme{professionalfonts}
\usepackage{times}
\usepackage{tikz}
\usepackage{amsmath}
\usepackage{verbatim}
\usetikzlibrary{arrows,shapes}

\author{Author}
\title{Presentation title}

\begin{document}

\tikzstyle{every picture}+=[remember picture]

\everymath{\displaystyle}

inner color=transparent!60,
outer color=transparent!0]

\begin{frame}
\frametitle{Rigid body dynamics}
\tikzstyle{na} = [baseline=-.5ex]

\begin{equation*}
\vec{a}_p = \vec{a}_o+\frac{{}^bd^2}{dt^2}\vec{r} +
\tikz[baseline]{
\node[anchor=base] (t1)
{$2\vec{\omega}_{ib}\times\frac{{}^bd}{dt}\vec{r}$};
} +
\tikz[baseline]{
{$\vec{\alpha}_{ib}\times\vec{r}$};
} +
\tikz[baseline]{
\node[fill=green!20,anchor=base] (t3)
{$\vec{\omega}_{ib}\times(\vec{\omega}_{ib}\times\vec{r})$};
}
\end{equation*}

\begin{tikzpicture}[overlay]
\path[clip] (current page.north west) rectangle (current page.south east);
(t1) circle (10cm) (t1) circle (1cm);

(t2) circle (10cm) (t2) circle (1cm);
\end{tikzpicture}
\end{frame}
\end{document}


You can see the results in beamer-fadings.pdf (will not work correctly in all pdf viewers)

Probably not exactly what you want, but it will hopefully give you some ideas.

• #10 Pascal, October 23, 2010 at 11:50 a.m.

This examples does not work with pdflatex on Ubuntu Maverick (pdfTeX 3.1415926-1.40.10-2.2 (TeX Live 2009/Debian)).

The arrows generated by \path appear very small, at the bottom left after the last line of text.

Any ideas why this may be the case?

• #11 J, February 7, 2012 at 8:38 p.m.

I am very impressed with this example. I'd very much like to use it. However, I cannot fully understand it.

How may I do the following 3 things: 1. Remove all of the colors from the equation. 2. Have only the 3rd version of the overlay and not have it preceded by the 2 partial overlays. 3. Remove the red text in bullets (e.g. Centripetal)

• #12 sarra, May 13, 2012 at 8:40 p.m.

@ Pascal you have forgetten to put this \tikzstyle{every picture}+=[remember picture] \everymath{\displaystyle} and it will work. :))

• #13 prachi, October 23, 2012 at 12:01 p.m.

I want to make my presentation in beamer which has graphics also. But I havenot beamer.cls file. Please send me the same so that I will try to construct .

• #14 Holly, November 30, 2012 at 7:51 p.m.

*You made some decent points there. I looked via that the internet for the issue and found most individuals will go along with with your website.

• #15 Schmendrik, January 13, 2013 at 2:51 p.m.

Here's an example where you use program code instead of an equation. It was a bit problematic because I wanted it to look like all other listing which are typeset with lstlisting. Here's the code for the colored part:

\tikz[baseline, remember picture, start chain = going right, node distance=0, text height=1.5ex, text depth=.25ex, inner sep=1pt] {
\node[anchor=base, fill=red!20, on chain]   (ret)   {\lstinline|int|};
\node[anchor=base, on chain]                (name)  {\lstinline|foo|};
\node[anchor=base, fill=blue!20, on chain]  (param) {\lstinline|(int a, int g)|};
\node[anchor=base, fill=green!20, on chain] (def)   {\lstinline|\{ return a + b; \}|};
}


Note the curly braces in the last part are escaped although they are inside lstinline. That's needed to "hide" them from \node.