Search code examples
graphnewlinegraphvizdot

graphviz no line break (.dot)


I'm working with graphviz on LinuxArch. If I print my .svg I use the command dot -Tsvg example.dot -o exampale.svg. My graph is printed and that works fine. I read some other questions on that topic Link 1, Link 2, also the documentation on graphviz.org didn't give me a clue.

Question: I want to line break in a node. How I can do it?

The following code is working, but not always. Full Code:

digraph G {
    //general settings
    graph [fontname="Arial"];
    node [fontname="Arial"];
    edge [fontname="Arial"];

    //data of graph
    subgraph cluster_1
    {
        label = "Cluster 1";
        style=filled;
        color="#E0E0E0";
        margin=20;
        node [style=filled,color=white];
        "I'm text" -> "I want a donat.";
        "I want a donat." -> a1[label="Love food,\nlove it so much!"];
    }

    subgraph cluster_2
    {
        label = "Cluster 2";
        style=filled;
        color="#E0E0E0";
        margin=20;
        node [style=filled,color=white];
        Start -> a2[label="sit amet,\nconsetetur"];
        a2 ->
        {
            b2[label="Lorem Impsum\ndollar sit amet."];
        }
    }
}

Result: (Green marked is working and the problem is Red marked.) enter image description here


Solution

  • It seems to me you are confusing node and edge declarations.

    Try changing the lines

        "I'm text" -> "I want a donat.";
        "I want a donat." -> a1[label="Love food,\nlove it so much!"];
    

    into

        a1[label="Love food,\nlove it so much!"];
        "I'm text" -> "I want a donat.";
        "I want a donat." -> a1;
    

    What this actually does is that a1 is defined as a node with a label. The node id a1 can then be used to declare edges between nodes.

    Here is an other example, with explicit node declarations for all nodes, and then the edge declarations using the node identifiers:

        imtext[label="I'm text"];
        donat[label="I want a donat."];
        a1[label="Love food,\nlove it so much!"];
    
        imtext -> donat -> a1;