1

I want to plot this graph in beamer and I don't know how! I want plot step by step this graph..

Step 1:

enter image description here

Step 2:

enter image description here

Step 3: enter image description here

Step 4: enter image description here

I write this follow

\documentclass{beamer}

\usepackage{tikz}

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


\begin{document}
% Declare layers
\pgfdeclarelayer{background}
\pgfsetlayers{background,main}

\begin{frame}
\frametitle{Prim's algorithm}

%% Adjacency matrix of graph
%% \  a  b  c  d  e  f  g
%% a  x  7     5
%% b  7  x  8  9  7
%% c     8  x     5
%% d  5  9     x 15  6
%% e     7  5 15  x  8  9
%% f           6  8  x 11
%% g              9  11 x

\tikzstyle{vertex}=[circle,fill=black!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}[scale=1.8, auto,swap]
    % Draw a 7,11 network
    % First we draw the vertices
    \foreach \pos/\name in {{(0,2)/a}, {(2,1)/b}, {(4,1)/c},
                            {(0,0)/d}, {(3,0)/e}, {(2,-1)/f}, {(4,-1)/g}}
        \node[vertex] (\name) at \pos {$\name$};
    % Connect vertices with edges and draw weights
    \foreach \source/ \dest /\weight in {b/a/7, c/b/8,d/a/5,d/b/9,
                                         e/b/7, e/c/5,e/d/10,
                                         f/d/6,f/e/8,
                                         g/e/9,g/f/11}
        \path[edge] (\source) -- node[weight] {$\weight$} (\dest);
    % Start animating the vertex and edge selection. 
    \foreach \vertex / \fr in {a/1,b/2,d/3,c/3}
        \path<\fr-> node[selected vertex] at (\vertex) {$\vertex$};
    % For convenience we use a background layer to highlight edges
    % This way we don't have to worry about the highlighting covering
    % weight labels. 
    \begin{pgfonlayer}{background}
        \pause
        \foreach \source / \dest in {b/a,d/a,d/b,c/b,e/b}
            \path<+->[selected edge] (\source.center) -- (\dest.center);
       % \foreach \source / \dest / \fr in {d/b/4,d/e/5,e/f/5,b/c/6,f/g/7}
          %  \path<\fr->[ignored edge] (\source.center) -- (\dest.center);
    \end{pgfonlayer}
\end{tikzpicture}
\end{figure}

\end{frame}

\end{document}

and problem is 1- my edges of graph is directed but this graph is not 2- in my graph steps are Sometimes chose double which means that in step b and d both chosen by a but this command step by step!!

7
  • 1
    You may want to add a minimal code frame, to show us what you've tried already and where you fail
    – sheß
    May 3 '16 at 12:02
  • I don't know how write this code! :(
    – maedeh
    May 3 '16 at 12:11
  • 1
    @maedeh At least, please include the code to generate the graphs, and the preamble that loads beamer.
    – darthbith
    May 3 '16 at 12:12
  • If you have nothing to start with, maybe a good starting point would be the answer in this queston: tex.stackexchange.com/questions/99119/…
    – sheß
    May 3 '16 at 12:14
  • Omg... how hard !! :(
    – maedeh
    May 3 '16 at 12:17
3

To make things only appear not immediately on a frame you can use \onslide<2-> What you want to appear\onslide<1->. Everything you write in between the two \onslide commands will only be visible on the second part of the frame. So in your example you want something like that:

\begin{frame}
    \begin{tikzpicture}
         %Draw your graph(always visible)
         \onslide<2->
         %Draw the red lines(only visible on the second part of the frame)
         \onslide<1->
    \end{tikzpicture}
    \pause
\end{frame}

The last \pause is necessary so that there is a chance to enter the second part of the frame where the red lines are shown.

4
  • problem is here I don't know how draw my graph!
    – maedeh
    May 3 '16 at 12:44
  • I think you should take a look at these examples: texample.net/tikz/examples/tag/graphs
    – BenjaminH
    May 3 '16 at 13:00
  • Oh..yes.thank you @ BenjaminH I'm try to do it
    – maedeh
    May 3 '16 at 13:02
  • Nobody any suggestion?
    – maedeh
    May 7 '16 at 6:07

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.