3

So I was using graphviz and wrote the following piece:

digraph MyGraph {
    rankdir=TB;
    size="8,5";
    node [shape = circle]; 1 2 3 4 5 6 7 8 9 r
    1->4
    1->4
    1->5
    1->5

    2->6
    2->6
    2->7
    2->7

    3->8
    3->8
    3->9
    3->9

    4->1
    4->1
    4->5
    4->5

    5->1
    5->1
    5->4
    5->4

    6->2
    6->2
    6->7
    6->7

    7->2
    7->2
    7->6
    7->6

    8->3
    8->3
    8->9
    8->9

    9->3
    9->3
    9->8
    9->8

    r->1
    r->1
    r->1

    r->2
    r->2
    r->2

    r->3
    r->3
}

Output: enter image description here

I don't like it that the edges overlap (meet). Is there any way to solve it automatically? if no, how to do it manually? I was trying to use overlap = false; but it didn't change anything. Also, tikzpicture could do the trick but I'm not sure how to do it. Furthermore, I tried to search some previous thread but they asked for different things.

abuka123
  • 133
  • 2
    Graphviz is off-topic for this site, so I'm voting to close. You should ask on Stackoverflow instead, with the risk of getting it closed there as a duplicate of https://stackoverflow.com/questions/3967600/how-to-prevent-edges-in-graphviz-to-overlap-each-other. From that question you could try the idea of origin and end ports, I got some improvements on your example with, e.g., 2->6:w 2->6 2:sw->7:nw 2:w->7:w. – Marijn Jan 30 '19 at 02:17
  • 2
    You could turn your question into a TeX question by switching gears. E.g. \documentclass[tikz,border=3.14mm]{standalone} \usetikzlibrary{graphs,graphdrawing} \usegdlibrary{layered} \begin{document} \begin{tikzpicture} \graph [layered layout, sibling distance=2cm, level distance=2cm, nodes={draw,circle,minimum size=1cm}] { r -> {1 -> 4 [xshift=-1cm] -> 5, 2 -> 6 -> 7 [xshift=0.5cm], 3 -> 8 -> 9 [xshift=0.5cm]}; }; \end{tikzpicture} \end{document} compiled with lualatex produces some similar graph (but not the arrows, which could be added). –  Jan 30 '19 at 02:53
  • @Marijn But why? I saw quite a lot of previous threads on that topic on this site. – abuka123 Jan 30 '19 at 11:31
  • @abuka123 it is a bit subtle - Graphviz is a different programming language unrelated to LaTeX, so it is off-topic to ask about how to do something in that language, however questions on how to integrate Graphviz with LaTeX (such as https://tex.stackexchange.com/questions/13675/use-graphviz-within-tex) are on-topic. As comparison, it is on-topic to ask about how to integrate LaTeX with Python (using pythontex for example) but it is not on-topic to ask about how to program in Python. – Marijn Jan 30 '19 at 21:04

1 Answers1

6

Welcome to TeX.SE! Here is a TikZ code that produces something of this sort. Unfortunately this is not too automatic. However, it may be the basis for some deeper application of the graph drawing algorithms.

\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{graphs,graphdrawing}
\usegdlibrary{layered} 
\begin{document}
\begin{tikzpicture}
 \graph [layered layout,  sibling distance=3cm, level distance=2cm,
 nodes={draw,circle,minimum size=1cm},edges={opacity=0}] {
     r  -> {1 -> 4 [xshift=-1cm] -> 5, 2 -> 6 [xshift=-0.5cm] -> 7 [xshift=0.5cm], 
     3 -> 8 [xshift=-0.5cm] -> 9 [xshift=0.5cm]};
 };
 \begin{scope}[every edge/.append style={-latex}]
  \foreach \X in {1,2,3}
  {\draw (r) edge[bend right=15] (\X) (r) edge (\X)
  (r) edge[bend right=-15] (\X);}
  \foreach \X/\Y in {1/4,4/5,2/6,6/7,3/8,8/9}
  {\draw(\X) edge[bend right=10] (\Y)
  (\X) edge[bend right=25] (\Y)
  (\Y) edge[bend right=10] (\X)
  (\Y) edge[bend right=25] (\X);}
  \foreach \X/\Y in {1/5,2/7,3/9}
  {\draw
  (\X) edge[bend left=10] (\Y)
  (\X) edge[bend left=20] (\Y)
  (\Y) edge[bend right=30] (\X)
  (\Y) edge[bend right=40] (\X);}
 \end{scope}
\end{tikzpicture}
\end{document}

enter image description here

  • Tried to compile it on latex4technics but without any success. Do you know why it fails? – abuka123 Jan 30 '19 at 11:40
  • @abuka123 I am sorry, I don't, I do not know what latex4technics is. (I compiled it with lualatex on a TeXLive 2018 distribution.) –  Jan 30 '19 at 13:20