9

I would like to have a new TikZ node appear behind the previous one. For instance in beamer presentations for highlighting parts of code.

I can do this if I place the \node before the new node and give it a hardcoded overlay number, but I'd rather keep the <+> overlay specification.

Of course any suggestions for a better way to do this are also welcome!

An example of what I'm trying to achieve:

\documentclass{beamer}
\usepackage{tikz,fancyvrb}
\usetikzlibrary{shapes,positioning}

\begin{document}
\begin{frame}[fragile]
  \begin{tikzpicture}
    \draw<2->[fill=blue!50] (-0.5\linewidth,-1em) rectangle (0.5\linewidth,1em);

    \node {
      \begin{minipage}{\linewidth}
\begin{Verbatim}
Please note this line!
\end{Verbatim}
      \end{minipage}
    };

  \end{tikzpicture}
\end{frame}
\end{document}

EDIT: example for using layers

\documentclass{beamer}
\usepackage{tikz,fancyvrb}
\usetikzlibrary{shapes,positioning,backgrounds}

\begin{document}

\begin{frame}[fragile]

  \begin{tikzpicture}

    \node<+-> at (0,0){
      \begin{minipage}{\linewidth}
        \VerbatimInput{queries/example.xquery}
      \end{minipage}
    };

    \begin{pgfonlayer}{background}
      \draw<+->[fill=blue!50] (-0.5\linewidth,-1em) rectangle (0.5\linewidth,1em);
    \end{pgfonlayer}

  \end{tikzpicture}

\end{frame}


\end{document}
7

There are two ways that I know of:

  1. Use PGF layers

  2. Use offsets in your incremental overlay specifications.

Here is an example with both.

\documentclass{beamer}
\usepackage{tikz,fancyvrb}
\usetikzlibrary{shapes,positioning}

\begin{document}

\begin{frame}[fragile]{using pgflayers}
  \pgfdeclarelayer{box}
  \pgfdeclarelayer{text}
  \pgfsetlayers{box,text}
  \begin{tikzpicture}
    \useasboundingbox (-0.5\linewidth,-1em) rectangle (0.5\linewidth,1em);
    \begin{pgfonlayer}{text}
    \node<+->{
      \begin{minipage}{\linewidth}
%\begin{Verbatim}
Please note this line!
%\end{Verbatim}
      \end{minipage}
    };
    \end{pgfonlayer}
    \begin{pgfonlayer}{box}
    \draw<+->[fill=blue!50] (-0.5\linewidth,-1em) rectangle (0.5\linewidth,1em);
    \end{pgfonlayer}
  \end{tikzpicture}
\end{frame}


\begin{frame}[fragile]{using offsets}
  \begin{tikzpicture}
    \useasboundingbox (-0.5\linewidth,-1em) rectangle (0.5\linewidth,1em);
    \draw<.(2)->[fill=blue!50] (-0.5\linewidth,-1em) rectangle (0.5\linewidth,1em);
    \node<+->{
      \begin{minipage}{\linewidth}
%\begin{Verbatim}
Please note this line!
%\end{Verbatim}
      \end{minipage}
    };
  \end{tikzpicture}
\end{frame}

\end{document}

I couldn't get the Verbatim environment to work; do you really need it?

  • Layers should do nicely. Thanks for the tip, I had missed it in the manual so far. I'll give it a try now. – nunolopes Dec 8 '10 at 18:58
  • I like the verbatim to display code, but I could use semiverbatim or listings if it makes a difference. I tried with the layers and works: – nunolopes Dec 8 '10 at 19:13
  • listings probably works better for displaying code. – Matthew Leingang Dec 8 '10 at 20:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.