改进 TikZ 图

改进 TikZ 图

我是 LaTeX 和 TikZ 的新手,我想改进以下图表:

\begin{tikzpicture}
\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};
\end{scope}
\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);
\end{scope}
\end{tikzpicture}

评论 :

  • 绿色节点标签太大。最好将它们缩小一点。
  • 我不希望标签位于节点上方。
  • 也许那些长标签可以是多行标签?

提前非常感谢您。

在此处输入图片描述

答案1

与您的图片略有不同:

在此处输入图片描述

通过相对定位稍微更简洁的代码获得:

\documentclass[tikz,margin=3mm]{standalone}
\usetikzlibrary{arrows.meta, positioning, quotes}

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

\begin{document}
    \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\}
                                              \end{multlined}$}},
            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);
    \end{tikzpicture}
\end{document}

答案2

您可以将\scriptsize或添加\small到节点的标签中,例如

{\scriptsize $T_9$} 

至于第二个问题,你可以使用度数代替 center。将其指向下方 270 度或 -90 度,然后根据需要调整距离:

\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};

在此处输入图片描述

相关内容