I'm a completely newbie with LaTeX and TikZ and I'd like to improve the following graph:

\begin{scope}[every node/.style={thick,draw,circle,minimum size=2em,inner sep=1}] % nodos
    \node [label={[green]right:0}] (1) at (3,5){1};
    \node [label={[green]right:$T_1$}](2) at (3,3.5){2};
    \node [label={[green]right:$T_1+T_2$}](3) at (3,2){3};
    \node [label={[green]left:$\sum_{i=1}^3T_i$}](4) at (1.5,0.5){4};
    \node [label={[green]right:$\sum_{i=1}^3T_i$}](5) at (4.5,0.5){5};
    \node [label={[green]left:$\sum_{i=1}^4T_i$}](6) at (0,-1){6};
    \node [label={[green]center:$\sum_{i=1}^3T_i+\max\{T_4,T_5\}$}] (7) at (3,-1){7};

    \node [label={[green]left:$\sum_{i=1}^4T_i+T_6$}](8) at (1.5,-2.5){8};
    \node [label={[green]right:$\sum_{i=1}^3T_i+T_5$}] (9) at (6,-1){9};
    \node [label={[green]center:$\sum_{i=1}^3T_i+\max\Big\{T_4+T_6+T_8,\max\big\{T_4,T_5\big\}+T_7,T_5+T_9\Big\}$}](10) at (4.5,-3.5){10};
\begin{scope}[every edge/.style={draw,thick}] % arcos
\draw[->] (1) edge node[left] {$T_1$} (2);
\draw[->] (2) edge node[left] {$T_2$} (3);
\draw[->] (3) edge node[left] {$T_3$} (4);
\draw[->] (3) edge node[right] {$T_3$} (5);
\draw[->] (4) edge node[left] {$T_4$} (6);
\draw[->] (4) edge node[right] {$T_4$} (7);
\draw[->] (5) edge node[left] {$T_5$} (7);
\draw[->] (5) edge node[right] {$T_5$} (9);
\draw[->] (6) edge node[left] {$T_6$} (8);
\draw[->] (7) edge node[left] {$T_7$}(10);
\draw[->] (8) edge node[below] {$T_8$} (10);
\draw[->] (9) edge node[right] {$T_9$} (10);

Comments :

  • The green node labels are too big. It would be nice to make them considerably smaller.
  • I don't want the labels to be over the nodes.
  • Maybe those long labels can be multi-line labels?

Thank you very much in advance.

enter image description here


Slightly different from your image:

enter image description here

obtained by slightly more concise code with relative positioning:

\usetikzlibrary{arrows.meta, positioning, quotes}

\usepackage{mathtools}% for multi line equation in label

    \begin{tikzpicture}[thick, auto,
     node distance = 10mm and 15mm,
every label/.style = {font=\footnotesize, text=teal},
state/.style = {draw,circle,minimum size=2em},
\node (n1) [state,label=right:0]          {1};
\node (n2) [state,label=right:$T_1$,
            below=of n1]            {2};
\node (n3) [state,label=right:$T_1+T_2$,
            below=of n2]            {3};
\node (n4) [state,label=left:{$\sum\limits_{i=1}^3T_i$},
            below  left=of n3]      {4};
\node (n5) [state,label=right:{$\sum\limits_{i=1}^3T_i$},
            below right=of n3]      {5};
\node (n6) [state,label=left:{$\sum\limits_{i=1}^4T_i$},
            below left=of n4]       {6};
\node (n7) [state,label=right:{$\sum\limits_{i=1}^3T_i+\max\{T_4,T_5\}$},
            below right=of n4]      {7};
\node (n8) [state,label=left:{$\sum\limits_{i=1}^4T_i+T_6$},
            below right=of n6]      {8};
\node (n9) [state,label=right:{$\sum\limits_{i=1}^3T_i+T_5$},
            below right=of n5]      {9};
\node (n10)[state,label={[yshift=-1em]right:{$\begin{multlined}
                        \sum_{i=1}^3T_i+\max\Big\{T_4+T_6 +\\
                        T_8,\max\big\{T_4,T_5\big\}+T_7,T_5 +T_9\Big\}
            below right=of n8]      {10};
\draw[-Straight Barb]
    (n1) edge ["$T_1$"] (n2)
    (n2) edge ["$T_2$"] (n3)
    (n3) edge ["$T_3$"] (n4)
    (n3) edge ["$T_3$"] (n5)
    (n4) edge ["$T_4$"] (n6)
    (n4) edge ["$T_4$"] (n7)
    (n5) edge ["$T_5$"] (n7)
    (n5) edge ["$T_5$"] (n9)
    (n6) edge ["$T_6$"] (n8)
    (n7) edge ["$T_7$"] (n10)
    (n8) edge ["$T_8$"] (n10)
    (n9) edge ["$T_9$"](n10);
  • This is absolutely awesome. However, I can't compile it. The (n10) node declaration gives me an error and also \draw[-Straight Barb].
    – Pierrot
    Mar 21 '17 at 16:55
  • I found out that the problem is the multi-line labels. I'll look into it.
    – Pierrot
    Mar 21 '17 at 17:15
  • Curious. The problem was the space between [yshift=-1em] and right. [yshift=-1em] right gives me a compilation error while [yshift=-1em]right works fine :). Thank you very, very much! Amazing solution!
    – Pierrot
    Mar 21 '17 at 17:34
  • I haven't this problem (with recent MikTeX). Maybe is your LaTeX installation to old. Try to update it. Anyway, I will remove this space.
    – Zarko
    Mar 21 '17 at 17:58
  • @Pierrot You might then consider accepting his answer by ticking the checkmark.
    – c.p.
    Mar 22 '17 at 6:01

You can add \scriptsize or \small to your node's label, e.g.

{\scriptsize $T_9$} 

As for the second issue, you can use degrees instead of center. Direct it below with 270 or -90 degrees and tweak the distance as the one you wish:

\node [label={[green,label distance=-3.6cm]-90:\scriptsize$\sum_{i=1}^3T_i+\max\Big\{T_4+T_6+T_8,\max\big\{T_4,T_5\big\}+T_7,T_5+T_9\Big\}$}](10) at (4.5,-3.5){10};

enter image description here


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.