LaTeX forum ⇒ Graphics, Figures & TablesGraph with nodes. Topic is solved

Information and discussion about graphics, figures & tables in LaTeX documents.
Novermars
Posts: 2
Joined: Tue Jan 07, 2014 5:58 pm

Graph with nodes.

Postby Novermars » Tue Jan 07, 2014 6:16 pm

Hello everybody!

For an assignment, I have to make a graph with 8 nodes and connect them. In the end, it should look something like this:

network_zps8648c5e4.png
network_zps8648c5e4.png (183.71 KiB) Viewed 4577 times


I found the TikZ-package to be useful, but still have some questions.
Currently, I have the following figure:

graph_zps0e33b37c.png
graph_zps0e33b37c.png (92.63 KiB) Viewed 4577 times


with the following code:
  1. \documentclass{article}
  2. \usepackage{tikz}
  3. \usetikzlibrary{arrows}
  4. \begin{document}
  5. \begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=2cm,
  6. thin,main node/.style={circle,fill=blue!20,draw,font=\sffamily\Large\bfseries}]
  7.  
  8. \node[main node] (1) {1};
  9. \node[main node] (2) [right of=1] {2};
  10. \node[main node] (3) [right of=2] {3};
  11. \node[main node] (4) [right of=3] {4};
  12. \node[main node] (5) [right of=4] {5};
  13. \node[main node] (6) [right of=5] {6};
  14. \node[main node] (7) [right of=6] {7};
  15. \node[main node] (8) [right of=7] {8};
  16.  
  17. \path[every node/.style={font=\sffamily\small}]
  18. (1) edge node [right] {100} (2)
  19. edge [bend left] node[right] {180} (3)
  20. edge [bend left] node[right] {300} (4)
  21. edge [bend left] node[right] {380} (5)
  22. edge [bend left] node[right] {620} (6)
  23. edge [bend left] node[right] {950} (7)
  24. edge [bend left] node[right] {1140}(8)
  25.  
  26. (2) edge node [right] {100} (3)
  27. edge [bend left] node[right] {180} (4)
  28. edge [bend left] node[right] {220} (5)
  29. edge [bend left] node[right] {400} (6)
  30. edge [bend left] node[right] {720} (7)
  31. edge [bend left] node[right] {820} (8)
  32.  
  33. (3) edge node [right] {100} (4)
  34. edge [bend left] node[right] {140} (5)
  35. edge [bend left] node[right] {260} (6)
  36. edge [bend left] node[right] {480} (7)
  37. edge [bend left] node[right] {580} (8)
  38.  
  39. (4) edge node [right] {100} (5)
  40. edge [bend left] node[right] {160} (6)
  41. edge [bend left] node[right] {300} (7)
  42. edge [bend left] node[right] {380} (8)
  43.  
  44. (5) edge node [right] {100} (6)
  45. edge [bend left] node[right] {180} (7)
  46. edge [bend left] node[right] {220} (8)
  47.  
  48. (6) edge node [right] {100} (7)
  49. edge [bend left] node[right] {120} (8)
  50.  
  51. (7) edge node [right] {100} (8);
  52. \end{tikzpicture}
  53. \end{document}

And to make an understatement, it looks messy as hell. Is it possible to make it look more like the figure above, so more spacing between the lines and the numbers either above or below the line?

Thanks in advance!
Last edited by cgnieder on Tue Jan 07, 2014 8:37 pm, edited 1 time in total.
Reason: uploaded picture to latex-community server (this is preferable to external links), changed inline code markup to block

Tags:

User avatar
tom
Posts: 73
Joined: Thu Apr 18, 2013 4:02 am

Postby tom » Thu Jan 16, 2014 3:44 pm

Replace
  1. edge [bend left] node[right] {180} (3)

with
  1. edge [bend left=60] node[above] {180} (3)


HTH, Tom

Novermars
Posts: 2
Joined: Tue Jan 07, 2014 5:58 pm

Postby Novermars » Mon Jan 20, 2014 8:21 pm

That works wonderful, thank you!


Return to “Graphics, Figures & Tables”

Who is online

Users browsing this forum: No registered users and 6 guests