3

I'm making a presentation using beamer and am wanting to connect the vertices of a graph using edges. I can do this using the following code.

\documentclass[xcolor=pdftex,dvipsnames,table]{beamer}
\usepackage{array}
\usepackage{amsthm,amsmath,amssymb}
\usepackage{multirow}
\usepackage{multicol}
\usepackage{url}
\usepackage{tikz}
\pgfdeclarelayer{background}
\pgfdeclarelayer{foreground}
\pgfsetlayers{background,main,foreground}

\begin{document}

\begin{frame}{Graph Theory}
\begin{tikzpicture}

\node[draw,circle,fill] (1) at (0,3.163) {};
\node[draw,circle,fill] (2) at (1.565,1.918) {};
\node[draw,circle,fill] (3) at (1,0) {};
\node[draw,circle,fill] (4) at (-1,0) {};
\node[draw,circle,fill] (5) at (-1.565,1.918) {};
\node[draw,circle,fill] (6) at (6,2.382) {};
\node[draw,circle,fill] (7) at (7,.65) {};
\node[draw,circle,fill] (8) at (5,.65) {};
\node [above=.25cm] at (1) {1};
\node [right=.25cm] at (2) {2};
\node [below right=.2cm] at (3) {3};
\node [below left=.2cm] at (4) {4};
\node [left=.25cm] at (5) {5};
\node [above=.25cm] at (6) {1};
\node [above right=.2cm] at (7) {2,3};
\node [above left=.2cm] at (8) {4,5};

\begin{pgfonlayer}{background}
\draw[blue, ultra thick] (1) -- (2) -- (3) -- (4) -- (5) -- (1);
\draw[red, ultra thick] (1) -- (3) -- (5) -- (2) -- (4) -- (1);
\draw[blue, ultra thick] (6) -- (7) -- (8) -- (6);
\draw[blue, ultra thick] (8) arc [radius=.4cm, start angle=20, end angle=380];
\draw[blue, ultra thick] (7) arc [radius=.4cm, start angle=160, end angle= 520];
\draw[red, ultra thick] (8) to [out=85,in=210,distance=.6cm] (6);
\draw[red, ultra thick] (6) to [out=330,in=95,distance=.6cm] (7);
\draw[red, ultra thick] (7) to [out=155,in=25,distance=.55cm] (8);
\draw[red, ultra thick] (8) to [out=335,in=205,distance=.55cm] (7);
\draw[red, ultra thick] (7) to [out=230,in=310,distance=.675cm] (8);
\end{pgfonlayer}

\end{tikzpicture}
\end{frame}

However, the triangle differs greatly from the easier to use code used below

\begin{frame}{Graph Theory}
\begin{tikzpicture}

\node[draw,circle,fill] (1) at (0,3.163) {};
\node[draw,circle,fill] (2) at (1.565,1.918) {};
\node[draw,circle,fill] (3) at (1,0) {};
\node[draw,circle,fill] (4) at (-1,0) {};
\node[draw,circle,fill] (5) at (-1.565,1.918) {};
\node[draw,circle,fill] (6) at (6,2.382) {};
\node[draw,circle,fill] (7) at (7,.65) {};
\node[draw,circle,fill] (8) at (5,.65) {};
\node [above=.25cm] at (1) {1};
\node [right=.25cm] at (2) {2};
\node [below right=.2cm] at (3) {3};
\node [below left=.2cm] at (4) {4};
\node [left=.25cm] at (5) {5};
\node [above=.25cm] at (6) {1};
\node [above right=.2cm] at (7) {2,3};
\node [above left=.2cm] at (8) {4,5};

\begin{pgfonlayer}{background}
\draw[blue, ultra thick] (1) -- (2) -- (3) -- (4) -- (5) -- (1);
\draw[red, ultra thick] (1) -- (3) -- (5) -- (2) -- (4) -- (1);
\draw[blue, ultra thick] (6) -- (7) -- (8) -- (6);
\draw[blue, ultra thick] (8) arc [radius=.4cm, start angle=20, end angle=380];
\draw[blue, ultra thick] (7) arc [radius=.4cm, start angle=160, end angle= 520];
\draw[red, ultra thick] (8) to [out=85,in=210,distance=.6cm] (6) to [out=330,in=95,distance=.6cm] (7) to [out=155,in=25,distance=.55cm] (8) to [out=335,in=205,distance=.55cm] (7) to [out=230,in=310,distance=.675cm] (8);
\end{pgfonlayer}

\end{tikzpicture}
\end{frame}

It seems that chaining the to commands together creates a path exactly from where the edge ended instead of from the node. Is there a way around this besides defining each each individually as I did in the previous code?

1

Your command is

\draw[red, ultra thick] (8) to [out=85,in=210,distance=.6cm] (6) 
     to [out=330,in=95,distance=.6cm] (7) 
     to [out=155,in=25,distance=.55cm] (8) 
     to [out=335,in=205,distance=.55cm] (7) 
     to [out=230,in=310,distance=.675cm] (8);

which doesn't use edge. It's a regular path, so the new segment starts where the last one finished. And they finished in node's borders because your black circles are nodes.

You can still use this shorter solution just fixing again where you want your new segment to start:

\draw[red, ultra thick] (8) to [out=85,in=210,distance=.6cm] (6) 
     (6) to [out=330,in=95,distance=.6cm] (7) 
     (7) to [out=155,in=25,distance=.55cm] (8) 
     (8) to [out=335,in=205,distance=.55cm] (7) 
     (7) to [out=230,in=310,distance=.675cm] (8);

or even shorter, reordering and using edges:

\draw[red, ultra thick] 
    (8) edge [out=85,in=210,distance=.6cm] (6) 
        edge [out=335,in=205,distance=.55cm] (7) 
    (6) edge [out=330,in=95,distance=.6cm] (7) 
    (7) edge [out=155,in=25,distance=.55cm] (8) 
        edge [out=230,in=310,distance=.675cm] (8);
  • That makes sense and works perfectly. Thanks! – JohnC Sep 22 '15 at 15:45

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.