3

I would like to progressively develop a graph created with during a beamer presentation. Here is a MWE:

\documentclass{beamer}

\usepackage{tikz}

\usetikzlibrary{graphs, graphdrawing}
\usegdlibrary{layered}

\begin{document}
\begin{frame}
    \begin{tikzpicture}
        \graph[layered layout]
        {%
            "1" -- {"2", "3"},

            {"2", "3"}  -- "4",
            % \only<2->{{"2", "3"}  -- "4",}
            {"2", "3"} -- "5",
            % \only<3->{{"2", "3"} -- "5",}

            {"4", "5"} -- "6",
            % \only<4->{{"4", "5"} -- "6",}

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

The commented lines show my intent but they lead to errors.

Ty for any help.

0

2 Answers 2

5

You could use the overlay-beamer-styles library:

% !TeX TS-program = lualatex

\documentclass{beamer}

\usepackage{tikz}

\usetikzlibrary{graphs, graphdrawing}
\usegdlibrary{layered}
\usetikzlibrary{overlay-beamer-styles}

\begin{document}

\begin{frame}
    \begin{tikzpicture}
        \graph[layered layout]
        {%
            "1" -- {"2", "3"},

            {"2", "3"} -- [draw on=<2->] "\alt<2->{4}{\phantom{4}}",
            
            {"2", "3"} -- [draw on=<3->] "\alt<3->{5}{\phantom{5}}",
            
            {"\alt<2->{4}{\phantom{4}}", "\alt<3->{5}{\phantom{5}}"} -- [draw on=<4->] "\alt<4->{6}{\phantom{6}}",

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

enter image description here

5
  • What about {"2", "3"} -- [draw on=<2->] "4" [visible on=<2->]? Then you can just keep the original node references. Aug 5 at 14:28
  • @JasperHabicht This gives a "funny" layout if used for the whole graph Aug 5 at 14:30
  • Does it? I get a nice result without any shifting. In the end visible on only sets the opacity. Aug 5 at 14:31
  • @JasperHabicht Ah, sorry, I must have made some error when testing. Aug 5 at 14:35
  • @JasperHabicht I'm looking forward to read your answer! Aug 5 at 14:35
4

samcarter already introduced the nice idea of using the overlay-beamer-styles library.

An alternative approach to their use of the \alt macro would be to use the visible on option provided by this library. It essentially sets the options opacity and text opacity to zero, which means that you won't get any layout shifts and you can even keep the node names. You would need to apply this option both to the edges and the nodes.

\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{graphs, graphdrawing}
\usegdlibrary{layered}
\usetikzlibrary{overlay-beamer-styles}

\begin{document}
\begin{frame}
    \begin{tikzpicture}
        \graph[layered layout]
        {%
            "1" -- {"2", "3"},
            
            {"2", "3"} -- [visible on=<2->] "4" [visible on=<2->],

            {"2", "3"} -- [visible on=<3->] "5" [visible on=<3->],

            {"4", "5"} -- [visible on=<4->] "6" [visible on=<4->],
        };
    \end{tikzpicture}
\end{frame}

\end{document}

enter image description here

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.