Creating a Presentation with LaTeX Beamer – Equations and tikz

July 23rd, 2010

Many presentations created using LaTeX beamer included mathematical equations and these can be easily included in a presentation and in this post we will consider using the tikz package to add various interesting elements to equations, such as lines between text on a slide and part of an equation.


Fast Tube by Casper

The examples on this page have been inspired by the good examples on global nodes detailed on texample.net. The example can be adapted to apply to equations for various statistical models and we will consider the model for a general row-column experiment design.

To create this example we need to make tikz available in our tex file by adding the following code to the preamble:

\usepackage{tikz}
\usetikzlibrary{arrows,shapes}

The second and third lines refer to particular elements of tikz that will be used in the example.

If we want to access nodes in different areas of our latex document we need to make use of the remember picture style and the easiest way to do this is to make a global declaration rather than on each specific picture:

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

The example will be the model for a row-column experiment design and we will have four elements in a bullet list that are linked by arrows to different parts of the equation, which in turn are highlighted in their own box.

We use the itemize environment to add the first bullet point:

\begin{itemize}
\item Overall mean \tikz[na] \node[coordinate] (s1) {};
\end{itemize}

At the end of the item we add a tikz node so that we can draw a line from the end of this line to one of the boxes in the equation. We also provide a name s1 so that it can be identified by tikz. This node uses a style to shift the location where the line starts from, that we need to define in our document using this code:

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

The next step is to create the equation and the nodes and background boxes for each element of the equation that will be linked to the bullet list. The code for the equation is shown here:

\begin{equation}
y_{ijk} = \tikz[baseline]{ \node[fill=blue!20,anchor=base,rounded corners=2pt]
  (d1) {$\mu$}; }
+ \tikz[baseline]{ \node[fill=red!20,anchor=base,rounded corners=2pt]
  (d2) {$r_{i}$}; }
+ \tikz[baseline]{ \node[fill=green!20,anchor=base,rounded corners=2pt]
  (d3) {$c_{j}$}; }
+ \tikz[baseline]{ \node[fill=yellow!20,anchor=base,rounded corners=2pt]
  (d4) {$t_{k}$}; }
+ \epsilon_{ijk}
\end{equation}

If we look closely at this code the latex for the equation itself is very straightforward and the complication comes from adding a tikz node to four of the elements of the equation. The nodes themselves have colours (blue/red/green/yellow) and rounded corners. They each have a label d1 to d4 so that tikz can draw lines between the bullet list and the elements of the equation.

We then finish off the bullet list with three more elements:

\begin{itemize}
\item Effect of row $i$ \tikz[na] \node[coordinate] (s2) {};
\item Effect of column $j$ \tikz[na] \node[coordinate] (s3) {};
\item Effect of treatment $k$ \tikz[na] \node[coordinate] (s4) {};
\end{itemize}

Each of the items in this bullet list have their own identifier s2 to s4 that we will use to draw arrows.

We create a separate picture environment for the four arrows linking the bullet list to the equation. Each element is defined as a path between two nodes with additional information about the shape of the arrow.

\begin{tikzpicture}[overlay]
\path[->] (s1) edge [bend left] (d1);
\path[->] (s2) edge [bend right] (d2);
\path[->] (s3) edge [out=0, in=-90] (d3);
\path[->] (s4) edge [out=0, in=-90] (d4);
\end{tikzpicture}

There are many variants on this example that could be incorporated in a presentation.

Other useful resources are provided on the Supplementary Material page. Also head over to texample.net for more examples of using the tikz package.

5 Responses to “Creating a Presentation with LaTeX Beamer – Equations and tikz”

  1. Lucian says:

    One question, not related to the content: what did you use to perform screen capture?

    Thanks,
    Lucian

  2. Ralph says:

    I have been using CamStudio to do screen capture. It is a reasonable primitive bit of software but for my purposes it fits the bill nicely.

  3. Nowegian says:

    awesome

  4. laubblatt says:

    Pretty nice to make equations more digestible!

    Could you also give links to the results such as a pdf? (it is more convenient than watching video (flash required,…)

    Last, is it possible to draw a line between a figure and and the equation?

  5. Ralph says:

    1) Will take a look to see where I put the pdf file for this demonstration.

    2) To draw a line between two places you need a tikz node in each location. If you place a tikz picture into your figure then I see no reason why you can’t draw the line that you have in mind.

Leave a Reply