6

I can draw a simple graph like this,

enter image description here

but if I want to draw a complex one like this, enter image description here

I feel frustrated. How could I do it?

The following are the codes which I drawn the first graph.

\documentclass[]{standalone}
\usepackage{wangyan}
\usetikzlibrary{arrows}
\begin{document}

\begin{tikzpicture}[<->,>=stealth',shorten >=1pt,auto,node distance=2cm, thick,main node/.style={circle,fill=blue!20,draw,font=\sffamily\Large\bfseries}]
  \node[main node] (1) {1};
  \node[main node] (2) [right of=1]  {2};
  \node[main node] (3) [right of=2]  {3};
   \node[main node] (4) [below of=3] {4};
  \node[main node] (5) [below  of=4] {5};
  \node[main node] (6) [left of=5]   {6};
  \node[main node] (7) [left of=6]   {7};
  \node[main node] (8) [below  of=1] {8};


  \path[every node/.style={font=\sffamily\small}]
    (1) edge [right] node[left]   {$$} (2)
    (2) edge [right] node[left]   {$$} (3)
    (3) edge [right] node[right]  {$$} (4)
    (4) edge [below] node[right]  {$$} (5)
    (5) edge [right] node[right]  {$$} (6)
    (6) edge [below] node[right]  {$$} (7)
    (7) edge [right] node[right]  {$$} (8)
    (8) edge [below] node[right]  {$$} (1) ;
\end{tikzpicture}
\end{document}
  • Not really sure what the question is. You feel frustrated just because it is more work? Or because there is something you don't know how to do? If the latter, what is it? – cfr Aug 15 '15 at 2:36
  • shorten > is only applied to one side of the double arrows. The addition shorten <=1pt makes the arrows symmetric. Also, ` (1) edge [right] node[left] {$$} (2)` can be reduced to (1) edge (2). – Heiko Oberdiek Aug 15 '15 at 2:48
  • @cfr the most tricky part is the node 9 and node 10, I placed them into the square of network, but node 10 is often mess with other node, for example, node 10 is at the position as node 4 – wayne Aug 15 '15 at 2:49
  • The syntax of= is deprecated; since you are loading the positioning library, you should use =of as in [below=of 3] – Gonzalo Medina Aug 15 '15 at 3:42
9

I'd position the nodes using shiftings in polar coordinates; in the example code below I placed the node "6" forst and use it as starting point to place all the other ones:

\documentclass[border=3pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows}

\begin{document}

\begin{tikzpicture}[
  <->,
  >=stealth',
  shorten >=1pt,
  shorten <=1pt,
  auto,
  thick,
  main node/.style={
    circle,
    fill=blue!20,
    draw,
    font=\sffamily\Large\bfseries,
    minimum size=25pt
  }
]
\node[main node] (6) {$6$};
\node[main node]
  at ([shift={(30:3cm)}]6) 
  (5) {$5$};
\node[main node]
  at ([shift={(150:3cm)}]6) 
  (7) {$7$};
\node[main node]
  at ([shift={(80:4cm)}]6) 
  (10) {$10$};
\node[main node]
  at ([shift={(115:4cm)}]6) 
  (9) {$9$};
\node[main node]
  at ([shift={(130:3cm)}]7) 
  (8) {$8$};
\node[main node]
  at ([shift={(110:3cm)}]8) 
  (1) {$1$};
\node[main node]
  at ([shift={(110:4cm)}]9) 
  (2) {$2$};
\node[main node]
  at ([shift={(85:3cm)}]10) 
  (3) {$3$};
\node[main node]
  at ([shift={(85:4cm)}]5) 
  (4) {$4$};
\path
  (1) edge (2)
  (2) edge (3)  
  (3) edge (4)  
  (4) edge (5)  
  (5) edge (6)  
  (6) edge (7)  
  (7) edge (8)
  (8) edge (1)
  (2) edge (8)
  (8) edge (3)
  (3) edge (10)
  (10) edge (6)
  (7) edge (9)
  (9) edge (2)
  (9) edge (10)
  (10) edge (5)
  ;  
\end{tikzpicture}

\end{document}

The result:

enter image description here

|improve this answer|||||

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.