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'm new here. I think this is the right place to ask this question.

Basically I would like to type a simple looking complete graph like this:

http://commons.wikimedia.org/wiki/File:Complex_network_K6_complete_graph.png

What I want is to place vertex and edge labels on top of the edges and vertices.

How would I go on doing that? What packages am I supposed to use and what commands should I type?

enter image description here

Sorry I should have included this picture to show what I have in mind. Thank you!

share|improve this question
    
Some graph examples made with tkz-graph package: altermundus.com/pages/tkz/graph/index.html and graphtheoryinlatex.blogspot.com.es –  Ignasi May 13 at 8:44
add comment

3 Answers 3

up vote 3 down vote accepted

You can use TikZ and its amazing graph library for this.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{graphs,graphs.standard}

\begin{document}
\begin{tikzpicture}
  \graph { subgraph K_n [n=8,clockwise,radius=2cm] };
\end{tikzpicture}
\end{document}

output

You can also add edge labels very easily:

\documentclass[tikz]{standalone}
\usepackage{tikz}
\usetikzlibrary{graphs,graphs.standard,quotes}

\begin{document}
\begin{tikzpicture}
  \graph[circular placement, radius=4cm,
         empty nodes, nodes={circle,draw}] {
    \foreach \x in {a,...,f} {
      \foreach \y in {\x,...,f} {
        \x -- \y;
      };
    };
    a --["3"'] b;
    a --["2"' near start] c;
    a --["1", near start] e;
    a --["1",] f;
    e --["2"'] f;
  };
  \foreach \x [count=\idx from 0] in {a,...,f} {
    \pgfmathparse{90 + \idx * (360 / 6)}
    \node at (\pgfmathresult:4.4cm) {\x};
  };
  \draw (a) edge[red, thick] node[black,left,pos=.2] {1} (d);
\end{tikzpicture}
\end{document}

output

share|improve this answer
    
You could define a macro which takes a parameter of the number of nodes and then separate each of the circle with degree 360/#1. I was about to post a solution along those lines, but probably better if you make that minor tweak. –  Peter Grill May 13 at 4:40
    
@PeterGrill Like I did in my edit? –  Sean Allred May 13 at 5:06
    
Looks good..... –  Peter Grill May 13 at 5:19
    
One problem with your labelled edges is that some labels are over-written. The labels 1<-->4 and 2<-->5 are hiding behind 3<-->6 (I think). –  corporal May 13 at 6:12
    
Thank you for this. How could I tweak this a bit so that it will look like that picture on my edit? Is there a way so that the edge labels and the vertex labels are outside? And how could I label them individually? Thank you! –  chowching May 13 at 6:45
show 2 more comments

run with xelatex

\documentclass[pstricks]{standalone}
\usepackage{pst-node,multido}
\begin{document}

\begin{pspicture}(-5,-5)(5,5)
\degrees[6]
\multido{\iA=0+1,\iB=1+1}{6}{\Cnode[radius=3mm](4;\iA){N\iB}\rput(N\iB){\iB}}
\multido{\iA=1+1}{5}{%
  \multido{\iB={\numexpr\iA+1\relax}+1}{\numexpr6-\iA}{\ncline{N\iA}{N\iB}}}
\multido{\iA=1+1}{5}{%   The same for the labels
  \multido{\iB={\numexpr\iA+1\relax}+1}{\numexpr6-\iA}{%
     \ncline[linestyle=none]{N\iA}{N\iB}\ncput*[npos=0.65]{\scriptsize$\iA\leftrightarrow\iB$}}}
\end{pspicture}

\end{document}

enter image description here

share|improve this answer
    
Sorry. 4<->6 and 5<->1 need some space to avoid overlapping each other. –  Please don't touch May 13 at 15:45
add comment

Just another suggestion with PSTricks. Readability level is kept high in both code and its output.

\documentclass[pstricks]{standalone}
\usepackage{pst-eucl}
\degrees[6]

\begin{document}

\begin{pspicture}(-5,-5)(5,5)
\multido{\iA=0+1,\iB=1+1}{6}{\Cnode[radius=3mm](4;\iA){N\iB}\rput(N\iB){\iB}}
\multido{\iA=1+1}{5}{%
    \multido{\iB={\numexpr\iA+1\relax}+1}{\numexpr6-\iA}{%
        \ncline[strokeopacity=.25]{N\iB}{N\iA}\ncput*[nrot=:U,npos=.8]{\scriptsize$\iA\leftrightarrow\iB$}}}
\end{pspicture}

\end{document}

enter image description here

share|improve this answer
    
6<->ϛ is still understandable, unless either 6 or 9 appears twice. –  Please don't touch May 13 at 7:23
    
Thank you for the effort! –  chowching May 13 at 16:49
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.