Improving graphviz layout

前端 未结 4 1383
青春惊慌失措
青春惊慌失措 2021-02-05 08:00

I have perfection paralysis when it comes to producing something graphic. If symmetries of the visual have not been fully explored, I have a harder time comprehending what is go

4条回答
  •  遥遥无期
    2021-02-05 08:14

    TikZ generates beautiful graph layouts. You can use a manual layout that lets you specify the minimum of hints, or you can ask for automatic layout. Defaults are good, and hooks exist to tweak to perfection.

    With the semi-manual layout you don't have to declare every detail, because you can

    • declare nodes as being 'above of', 'below right of', etc. relative to other nodes.
    • place your nodes on a raster by entering them as a matrix: very convenient if you want to leave some positions empty.
    • easily specify in what direction edges should enter, leave, bend, or take corners

    For automatic layout, TikZ's graphdrawing library has some pretty slick algorithms.

    Here is an example of manual layout and the TeX code used to obtain it:

    example graph

    \usepackage{pgf}
    \usepackage{tikz}
    \usetikzlibrary{arrows,automata}
    \usepackage[latin1]{inputenc}
    \begin{document}
    \begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=2.8cm,
                        semithick]
      \tikzstyle{every state}=[fill=red,draw=none,text=white]
    
      \node[initial,state] (A)                    {$q_a$};
      \node[state]         (B) [above right of=A] {$q_b$};
      \node[state]         (D) [below right of=A] {$q_d$};
      \node[state]         (C) [below right of=B] {$q_c$};
      \node[state]         (E) [below of=D]       {$q_e$};
    
      \path (A) edge              node {0,1,L} (B)
                edge              node {1,1,R} (C)
            (B) edge [loop above] node {1,1,L} (B)
                edge              node {0,1,L} (C)
            (C) edge              node {0,1,L} (D)
                edge [bend left]  node {1,0,R} (E)
            (D) edge [loop below] node {1,1,R} (D)
                edge              node {0,1,R} (A)
            (E) edge [bend left]  node {1,0,R} (A);
    \end{tikzpicture}
    \end{document}
    

提交回复
热议问题