TikZ 的依赖图

TikZ 的依赖图

我尝试使用 tikz 做这样的事情:

在此处输入图片描述

我尝试这样做

\begin{tikzpicture}[every node/.style={draw,thick,
    align=justify, % Blocksatz in Noden
    anchor=north% Anker der child node für level distance
}]

\tikzstyle{level 1}=[sibling distance=60mm]
\tikzstyle{level 2}=[sibling distance=60mm]
\tikzstyle{level 3}=[sibling distance=30mm]

\node {$T_1$}
child {node {$T_9$}; &
\node {$T_2$}; &
child {node {$T_3$}
    child{ node {$T_5$}}
    child{ node {$T_6$}
    }
};
\end{tikzpicture}

但看起来,我把一些事情搞砸了。非常感谢您的帮助!

答案1

这是一个借助软件包的解决方案

% arara: pdflatex

\documentclass{article}
\usepackage{tikz-cd}

\begin{document}
\begin{tikzcd}[cells={nodes={draw}}]
T_1 \arrow{d} & T_2 & T_3 & T_4 \arrow{dl} \arrow{d} \arrow{dr} \arrow{drr} & &\\
T_9 & & T_5 & T_6 & T_7 & T_8
\end{tikzcd}
\end{document} 

在此处输入图片描述

你可以根据自己的需要调整一切:

\documentclass{article}
\usepackage{tikz-cd}

\begin{document}
\begin{tikzcd}[%
    ,cells={nodes={draw,minimum width=.7cm,minimum height=.7cm}}
    ,column sep=1em%,row sep=...
    ,every arrow/.append style={-latex}
    ]
T_1 \arrow{d} & T_2 & T_3 & T_4 \arrow[start anchor = south west, end anchor = north east]{dl} \arrow{d} \arrow[start anchor = south east, end anchor = north west]{dr} \arrow{drr} & &\\
T_9 & & T_5 & T_6 & T_7 & T_8
\end{tikzcd}
\end{document} 

在此处输入图片描述

答案2

forest使用phantom根音符对齐第一行节点的解决方案:

\documentclass[tikz,border=5pt]{standalone}
\usepackage{forest}

\begin{document}

\begin{forest}
  for tree={
    draw,
    thick,
    edge path={
      \noexpand\path [-latex, thick, \forestoption{edge}] (!u.parent anchor) -- (.child anchor) \forestoption{edge label};
    }
  }
    [, phantom
      [$T_1$
        [$T_9$
        ]
      ]
      [$T_2$
      ]
      [$T_3$
      ]
      [$T_4$, calign primary child=2, calign=child
        [$T_5$
        ]
        [$T_6$
        ]
        [$T_7$
        ]
        [$T_8$
        ]
      ]
    ]
\end{forest}

\end{document}

森林树木

答案3

tikz 树解决方案。从父节点到第 1 级的线条通过样式被抑制

edge from parent/.style={draw=none}},

在此处输入图片描述

代码

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{trees,arrows,positioning}
\begin{document}

\begin{tikzpicture}
[level distance=1cm,every node/.style={draw, thick, 
    align=justify, % Blocksatz in Noden
    anchor=north% Anker der child node für level distance
},->,>=stealth',]

%\tikzstyle{level 1}=[sibling distance=10mm]
%\tikzstyle{level 2}=[sibling distance=20mm]
\tikzset{level 1/.style={sibling distance=2cm, edge from parent/.style={draw=none}},
level 2/.style={sibling distance=1.35cm,edge from parent/.style={draw}}
}

\node[draw=none]{}
child {node {$T_1$}
         child {node {$T_9$}}}
child{node[] {$T_2$}}
child{node[] {$T_3$}}
child{node[] {$T_4$}
         child{ node[] {$T_5$}}
         child{ node {$T_6$}}
         child{ node {$T_7$}}
         child{ node {$T_8$}}};
\end{tikzpicture}
\end{document}

答案4

PSTricks 解决方案:

\documentclass{article}

\usepackage{pstricks-add}

\begin{document}

\psset{
  framesize = 24pt,
  nodesep = 0pt,
  arrows = ->
}
\begin{pspicture}(9.75,2.75)
  \multido{\rA = 0.5+1.75, \rB = 4+1.75, \iA = 1+1, \iB = 5+1}{4}{
    \fnode(\rA,2.25){T\iA}
    \rput(\rA,2.25){$T_{\iA}$}
    \fnode(\rB,0.5){T\iB}
    \rput(\rB,0.5){$T_{\iB}$}
%    \ncline{T4}{T\iB} % not working for some reason
  }
  \fnode(0.5,0.5){T9}
  \rput(0.5,0.5){$T_{9}$}
  \ncline{T1}{T9}
  \ncline{T4}{T5}
  \ncline{T4}{T6}
  \ncline{T4}{T7}
  \ncline{T4}{T8}
\end{pspicture}

\end{document}

输出

笔记

我不知道为什么注释掉的行不起作用,以及为什么我必须使用环境中的最后四行pspicture

相关内容