[Tex/LaTex] Basic undirected graphs in TikZ

graphstikz-graphstikz-pgf

Hey TeX Stack Exchangers,

I have to draw some really basic undirected graphs in TikZ and struggling to find documentation that fits my needs. Each of my graphs has 10 edges and an equal number of degrees per vertice. I want to draw 3 graphs as follows:

  1. A graph with 20 nodes each with a degree of 1
  2. A graph with 10 nodes each with a degree of 2
  3. A graph with 5 nodes each with a degree of 4

I obviously don't want to hand code all of these nodes and edges. I've been playing around with loops in TikZ but it is really frustrating. The closest thing I found for graph #2 is this link but it isn't much help.

Thanks!

Best Answer

With a special package for graphs it is easy:

\documentclass{article}

\usepackage{tkz-berge}
\begin{document}

\begin{tikzpicture}
\SetVertexMath
\grEmptyPath[prefix=v,RA=2,RS=0]{5}
\grEmptyPath[prefix=w,RA=2,RS=3]{5}
\EdgeIdentity{v}{w}{5}
\end{tikzpicture}

\begin{tikzpicture}

\SetVertexMath
\grCycle[RA=2]{10}
\end{tikzpicture}

\begin{tikzpicture}

\SetVertexMath
\grComplete[RA=2]{5}
\end{tikzpicture}

\end{document} 

See documentation of tkz-berge.

enter image description here

Related Question