Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have a problem with my graph and my background environment to highlight the edges in the "last" of my slides.

First I tried this:

\begin{frame}
\frametitle{Graphmodell Beispiel}

\tikzstyle{vertex}=[circle,fill=white!25,minimum size=20pt,inner sep=0pt]
\tikzstyle{selected vertex} = [vertex, fill=red!24]
\tikzstyle{edge} = [draw,thick,-]
\tikzstyle{weight} = [font=\small]
\tikzstyle{selected edge} = [draw,line width=5pt,-,red!50]
\tikzstyle{ignored edge} = [draw,line width=5pt,-,black!20]

\begin{figure}
\begin{tikzpicture}[every node/.style={circle,draw},level 1/.style={sibling distance=30mm},level 2/.style={sibling distance=20mm}
]
    %\tikzstyle{every node}=[circle,draw]
    \only<1,2>{\node[vertex] (1) {1}
        child {node[vertex] (2) {2}
            child{node[vertex] (3){3}}
            child{node[vertex] (4){4}}
        }
        child { node[vertex] (5) {5}
            child {node[vertex](6) {6}}
            child {node[vertex] (7){7}
                child{node[vertex] (8){8}}
                child{node[vertex] (9){9}}
            }
        }};
    \only<3>{\node[vertex, label=right:$T_{k}$] (1) {1}
        child {node[vertex, label=left:$T_{k-in}$] (2) {2}
            child{node[vertex] (3){3}}
            child{node[vertex] (4){4}}
        }
        child { node[vertex, label=right:$T_{k-out}$] (5) {5}
            child {node[vertex](6) {6}}
            child {node[vertex] (7){7}
                child{node[vertex] (8){8}}
                child{node[vertex] (9){9}}
            }
        }};

        \begin{pgfonlayer}{background}
        \pause
        \foreach \source / \dest in {1/2,2/4,1/5,5/7,7/8}
            \path[selected edge] (\source.center) -- (\dest.center);
    \end{pgfonlayer}
\end{tikzpicture}
\end{figure}
\visible<3->{\begin{center}Fahrzeug $k \in k^{+}$ mit Start-Endpunktvektor $(4,8)$\end{center}}
\end{frame}

It worked just fine besides the fact that the graph was switching the positions slightly because of using \only instead of \visible.

But when I replace \only with \visible I don't know how to "background" my edges any more, because it gives me the error that the vertices aren't found.

\begin{frame}
\frametitle{Graphmodell Beispiel}

\tikzstyle{vertex}=[circle,fill=white!25,minimum size=20pt,inner sep=0pt]
\tikzstyle{selected vertex} = [vertex, fill=red!24]
\tikzstyle{edge} = [draw,thick,-]
\tikzstyle{weight} = [font=\small]
\tikzstyle{selected edge} = [draw,line width=5pt,-,red!50]
\tikzstyle{ignored edge} = [draw,line width=5pt,-,black!20]

\begin{figure}
\begin{tikzpicture}[every node/.style={circle,draw},level 1/.style={sibling distance=30mm},level 2/.style={sibling distance=20mm}
]
    %\tikzstyle{every node}=[circle,draw]
    \node{{\visible<1>{[vertex] (1) {1}
        child {node[vertex] (2) {2}
            child{node[vertex] (3){3}}
            child{node[vertex] (4){4}}
        }
        child { node[vertex] (5) {5}
            child {node[vertex](6) {6}}
            child {node[vertex] (7){7}
                child{node[vertex] (8){8}}
                child{node[vertex] (9){9}}
        }
        }}}};
    \only<3>{\node[vertex, label=right:$T_{k}$] (1) {1}
        child {node[vertex, label=left:$T_{k-in}$] (2) {2}
            child{node[vertex] (3){3}}
            child{node[vertex] (4){4}}
        }
        child { node[vertex, label=right:$T_{k-out}$] (5) {5}
            child {node[vertex](6) {6}}
            child {node[vertex] (7){7}
                child{node[vertex] (8){8}}
                child{node[vertex] (9){9}}
            }
        }};

    \begin{pgfonlayer}{background}
        \pause
        \foreach \source / \dest in {1/2,2/4,1/5,5/7,7/8}
            \path[selected edge] (\source.center) -- (\dest.center);
    \end{pgfonlayer}
\end{tikzpicture}
\end{figure}
\visible<3->{\begin{center}Fahrzeug $k \in k^{+}$ mit Start-Endpunktvektor $(4,8)$\end{center}}
\end{frame}

Does anybody know how to get out of this trouble?

P.S: Thanks Claudio for the format. I understood that you just have to indent inside the code

share|improve this question
    
It's almost the same problem of Mindmap tikzpicture in beamer (reveal step by step): Daniel's solution is the recommended one. –  Claudio Fiandrino Feb 20 '13 at 17:17
add comment

1 Answer 1

up vote 4 down vote accepted

As said in the comment, the Daniel's approach from Mindmap tikzpicture in beamer (reveal step by step) allows to avoid the so called jumping effect (the movement of the graph you perceive); this is a well known problem and on the site there are several references; some of them are:

Notice that, in your example, you just have to apply the style visible on to the nodes (and labels) that have to appear later on, not to all child nodes (that's something required if you want to make the whole vertex appear later on).

The code:

\documentclass{beamer}
\usepackage{lmodern}
\usepackage{tikz}
\usetikzlibrary{backgrounds}

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

\begin{document}
\begin{frame}
\frametitle{Graphmodell Beispiel}

\tikzset{vertex/.style={circle,fill=white!25,minimum size=20pt,inner sep=0pt}}
\tikzset{selected vertex/.style={vertex, fill=red!24}}
\tikzset{edge/.style={draw,thick,-}}
\tikzset{weight/.style={font=\small}}
\tikzset{selected edge/.style={draw,line width=5pt,-,red!50}}
\tikzset{ignored edge/.style={draw,line width=5pt,-,black!20}}

\begin{center}

\begin{tikzpicture}[every node/.style={circle,draw},level 1/.style={sibling distance=30mm},level 2/.style={sibling distance=20mm}
]
    \node[vertex] (1) {1}
        child {node[vertex] (2) {2}
            child{node[vertex] (3){3}}
            child{node[vertex] (4){4}}
        }
        child { node[vertex] (5) {5}
            child {node[vertex](6) {6}}
            child {node[vertex] (7){7}
                child{node[vertex] (8){8}}
                child{node[vertex] (9){9}}
            }
        };
    \node[vertex,visible on=<3>, label={[visible on=<3>]right:$T_{k}$}] (1) {1}
        child {node[vertex, visible on=<3>, label={[visible on=<3>]left:$T_{k-in}$}] (2) {2}
            child{node[vertex] (3){3}}
            child{node[vertex] (4){4}}
        }
        child { node[vertex, visible on=<3>,label={[visible on=<3>]right:$T_{k-out}$}] (5) {5}
            child {node[vertex](6) {6}}
            child {node[vertex] (7){7}
                child{node[vertex] (8){8}}
                child{node[vertex] (9){9}}
            }
        };

        \begin{pgfonlayer}{background}
        \pause
        \foreach \source / \dest in {1/2,2/4,1/5,5/7,7/8}
            \path[selected edge] (\source.center) -- (\dest.center);
    \end{pgfonlayer}
\end{tikzpicture}
\end{center}
\visible<3->{\begin{center}Fahrzeug $k \in k^{+}$ mit Start-Endpunktvektor $(4,8)$\end{center}}
\end{frame}

\end{document}

The result:

enter image description here

All the styles defined via \tikzstyle in your example have been changed into \tikzset as per Should \tikzset or \tikzstyle be used to define TikZ styles?.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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