Overlays for bar charts (take 2)

A while back I posted about using overlays for bar charts to show one value at a time. For my latest presentation I had a similar but slightly different wish: show all values for one system at a time, one system after the other.

Easily done, I just adapt the code from my previous post to show all values at the same time:

\newcommand{\addplotoverlay}[3][]{
\alt<#3->{
\addplot+ [ybar,#1] coordinates {#2}; 
}{
\addplot+ [ybar,#1] coordinates {(Xcoord1,0)}; % + don't show zero values in plot
}
}

This is specific to my plot, Xcoord1 is one of my symbolic x-coordinates in the plot. Other than that, the code is completely independent from the used coordinates and the number of them, which makes it more flexible than my old stuff.

Usage (this will let seagreen bars at the given coordinates appear on slide 2):

\addplotoverlayrank[seagreen]{(Xcoord1, 0.331) (Xcoord2, 0.095)}{2}

Dependency trees with tikz-dependency

There is a package for drawing dependency trees in LaTeX called tikz-dependency:

\usepackage{tikz-dependency} % draw example with dependency tree

First the sentence is defined inside a deptext environment. You could add more rows to the sentence, e.g., for lemmas or parts-of-speech.
The edges between words are given with depedge commands (outside the deptext environment). Edges can in theory go both ways, but it looks better if they go from the head to the child. Here is an example dependency tree for a sentence:

\begin{dependency}
\begin{deptext}
It \& has \& a \& larger \& LCD \& than \& the \& T3i \& .\\
\end{deptext}
\deproot{3}{ROOT}
\depedge{2}{1}{NMOD}
\depedge{5}{3}{NMOD}
\depedge{5}{4}{NMOD}
\depedge{2}{5}{NMOD}
\depedge{5}{6}{PMOD}
\depedge{8}{7}{AMOD}
\depedge{6}{8}{PRD}
\end{dependency}

Besides drawing dependency trees, the package is also useful to create nice mark-up for words and phrases. The command is wordgroup which is inserted at the same place as the dependency edges and works upon the elements of the deptext The following draws a red box around words 7 and 8 in the sentence above (the 1 stands for the row):

\wordgroup[group style={fill=red!30, draw=red}]{1}{7}{8}{a}

There are lots of styling options for nodes, edges and word groups. I use the following in my thesis (this defines a style that combines options for both the dependency and the deptext environment, I just use the same in both):

\depstyle{depex}{%
   edge style = {gray},
   group style={inner sep=.2ex},
   column sep=0.5em,
   edge unit distance=2ex,
   edge horizontal padding=0.5ex,
   row sep=0.2em,
   label style={draw=none,font=\scriptsize},
   edge vertical padding=0.4ex,
}

I want all mark-up of all word groups to be styled the same way, so I don’t want to write the part with fill and draw all the time with different colors. And if I want to change the percentage of white, I would like to do it at one place for all nodes. So I have written a macro that only expects the color to be given:

\tikzset{
   coloring of/.style={fill=#1!30, draw=#1},
}

And finally, for presentations with dependency trees I want to be able to use overlays, i.e., to show a word group at a specific time. For edges you can use the normal \visible command from beamer, but for word groups it does not work for some reason. So this is a macro that does work and shows word groups only on specific slides (I got this from LaTeX Stack Exchange):

\tikzset{
    invisible/.style={opacity=0},
    visible on/.style={alt={#1{}{invisible}}},
    alt/.code args={<#1>#2#3}{%
      \alt<#1>{\pgfkeysalso{#2}}{\pgfkeysalso{#3}}},
}

Finally, here an example of using the two macros:

\wordgroup[group style={coloring of=predicatecolor},visible on=<4->]{1}{2}{4}{pred}

Handouts from slides

Creating handouts from slides created with LaTeX beamer is simple. Just specify the option “handout” in the documentclass:

\documentclass[handout]{beamer}

In your slides, you can use the marker presentation and handout to give specific instructions that apply only when the pdf is created in presentation mode or in handout mode. So for example you can have different templates for your slides [there are spaces around the < because otherwise they are not displayed in this blog... delete them when you write real LaTeX]:

\mode < presentation >
{
\usetheme{Madrid}
}
\mode < handout >
{
\usetheme{Szeged}
\usecolortheme{beaver}
}

You can have things only on the handout or only on the slides:

\visible<1->{This is the same for handout and slides.}
\visible<1-|handout:0>{This won't be in the handout.}
\visible<1|handout:2>{This is on the same slide for the presentation,
but on a different slide for the handout.}
\visible<2|handout:1>{This is on a different slide for the presentation,
but on the same slide for the handout.}

Overlays and verbatim

Another weird LaTeX problem. I have a piece of code on my slide and the result it gives. I want to change the code slightly and visualize the change in the result. Normally in LaTeX beamer slides, I would use overlays like this:

Query:
\begin{verbatim}
some code
\alt<2>{slightly changed code on slide 2}{original code on slide 1}
some more code
\end{verbatim}

Result:
this item is the same in both
\visible<1>{this one is only there for the original code}
\visible<2>{this one is only there for the changed code}

So far, so good. The code is in a verbatim environment, so I have cannot put the overlay around the line I want to change, but that’s fine, let’s make it an alternative around the whole verbatim part. But, unfortunately, the problem is that you cannot put a verbatim environment inside of overlays (learn why). So you have to hack it. This is the code I want, the line with FILTER is the one I only want to have on the second slide:

\begin{verbatim}
SELECT ?book ?author ?releasedate
WHERE {
   ?book dbo:author ?author .
   {
      ?book dbp:releaseDate ?releasedate . 
   } UNION {
      ?book dbp:pubDate ?releasedate . 
   }
   FILTER (?releasedate > 1950)
}
\end{verbatim}

Like in my post on using verbatim inside of verbatim, I have to end the verbatim environment prematurely, skip back over the space and then I can include the overlay inside of verb.

\begin{verbatim}
SELECT ?book ?author ?releasedate
WHERE {
   ?book dbo:author ?author .
   {
      ?book dbp:releaseDate ?releasedate . 
   } UNION {
      ?book dbp:pubDate ?releasedate . 
   }
\end{verbatim}
\vspace{-0.5\baselineskip}
\verb|  |\visible<2>{\texttt{FILTER (?releasedate > 1950 )}}\\
\verb|}|
\\

Not the most elegant way, but it works…

Overlays for bar charts

Yesterday I posted about creating bar charts with TikZ and pgfplots.

Today I want to present a command to make the bars of one data series (i.e., one of my systems) appear one after the other on a beamer LaTeX slide.

This is the code to put into your preamble:

\newcounter{MyNextSlide}
\newcounter{MyNextNextSlide}
\newcommand{\addplotoverlay}[5][]{
\setcounter{MyNextSlide}{#5}
\stepcounter{MyNextSlide}
\setcounter{MyNextNextSlide}{\theMyNextSlide}
\stepcounter{MyNextNextSlide}
\alt<#5->{\only<#5->{\alt<\theMyNextSlide->{\alt<\theMyNextNextSlide->{
\addplot+ [ybar,#1] coordinates {#2 #3 #4}; 
}{
\addplot+ [ybar,#1] coordinates {#2 #3}; 
}}{
\addplot+ [ybar,#1] coordinates {#2}; 
}}}{
\addplot+ [ybar,#1] coordinates {(PI,0)}; % + don't show zero values in plot
}
}

Usage (‘first slide’ refers to the slide on which value 1 should first appear, it will stay and the slide afterwards will add value 2, the slide after that will add value 3):

\addplotoverlay [color or other options] {value 1}{value 2}{value 3}{first slide}

This depends on there being three data points in a data series and I have hardcoded the x coordinate PI. You’ll probably need to adjust this before you are able to do something useful with this code.