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.
En français: TeXnique.fr.

```
\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]
\begin{itemize}[<+-| alert@+>]
\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*}
\begin{itemize}[<+-| alert@+>]
\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}
```

## Comments

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

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.

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

@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

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.

@Nasimul: Try inserting

`\RequirePackage{atbegshi}`

at the start of your document:Apparently there is an incompatability between Beamer/PGF and hyperref.

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

@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.

Here is a basic example using fadings:

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.

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?

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)

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

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 .

*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.

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:Note the curly braces in the last part are escaped although they are inside

`lstinline`

. That's needed to "hide" them from`\node`

.Adding comments is currently not enabled.