我如何设计一个节点形状像这张照片的树形图?

我如何设计一个节点形状像这张照片的树形图?

在此处输入图片描述

请帮帮我!非常感谢!

答案1

有了forest它就简单多了。

\documentclass[tikz,border=3mm]{standalone}
\usepackage[edges]{forest}
\begin{document}
\begin{forest}
forked edges,
    for tree={draw,grow=south,
    edge={-stealth,semithick},
    text centered,
    anchor=center,
    l sep=2em,  
    fork sep=1em,
    font=\sffamily,
    text width=2cm,
    minimum height=0.8cm,
    }
 [def
  [abc,alias=A]
  [ghi,alias=B]
  [klm,alias=C]
 ]
\begin{scope}[thick]
 \draw[red,shorten >=-1ex, shorten <=-1ex] ([yshift=1ex]A.north west) --
     ([yshift=-1ex]A.south east);
 \draw[red,shorten >=-1ex, shorten <=-1ex] ([yshift=1ex]A.north east) --
     ([yshift=-1ex]A.south west);
 \draw[blue,shorten >=-0.4ex, shorten <=-0.4ex] ([yshift=0.5ex]C.west) -- ([yshift=0.5ex]C.east);
 \draw[blue,shorten >=-0.4ex, shorten <=-0.4ex] ([yshift=-0.5ex]C.west) -- ([yshift=-0.5ex]C.east);
\end{scope}
\end{forest}
\end{document}

在此处输入图片描述

答案2

这是使用基本 tikz 的另一种解决方案,假设问题中的直线是历史遗留而不是逻辑必然。

在此处输入图片描述

\documentclass[border=2mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}[
    % define abbreviations for frequently used combinations of options
    box/.style={draw,minimum width=2cm,minimum height=1cm},
    crossout/.style={thick,red,shorten >=-0.4ex, shorten <=-0.4ex},
    strikeout/.style={thick,blue,shorten >=-0.4ex, shorten <=-0.4ex}
  ]
  % \node [options] (name) {contents};
  \node [box]                    (DEF) {def};
  \node [box,below=of DEF]       (GHI) {ghi};
  \node [box,below left=of DEF]  (ABC) {abc};
  \node [box,below right=of DEF] (KLM) {klm};

  % Lines
  \draw[->] (DEF) edge             (GHI);
  \draw[->] (DEF) edge[bend right] (ABC);
  \draw[->] (DEF) edge[bend left]  (KLM);

  % Decorations
  \draw[crossout]  ([yshift=1ex]ABC.north west) -- ([yshift=-1ex]ABC.south east);
  \draw[crossout]  ([yshift=1ex]ABC.north east) -- ([yshift=-1ex]ABC.south west);
  \draw[strikeout] ([yshift= 0.5ex]KLM.west) -- ([yshift= 0.5ex]KLM.east);
  \draw[strikeout] ([yshift=-0.5ex]KLM.west) -- ([yshift=-0.5ex]KLM.east);
\end{tikzpicture}
\end{document}

答案3

这是使用基本 Tikz 命令的答案。

在此处输入图片描述

\documentclass[border=2mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}[
    % abbreviations for frequently used combinations of options
    box/.style={draw,minimum width=2cm,minimum height=1cm},
    crossout/.style={thick,red,shorten >=-0.4ex, shorten <=-0.4ex},
    strikeout/.style={thick,blue,shorten >=-0.4ex, shorten <=-0.4ex}
  ]
  % \node      [options] (name) {contents};
  % \coordinate[options] (name);
  \node      [box]              (DEF) {def};
  \coordinate[below=of DEF]     (X);
  \node      [box,below=of X]   (GHI) {ghi};
  \node      [box,left=of GHI]  (ABC) {abc};
  \node      [box,right=of GHI] (KLM) {klm};

  % Lines
  \draw[->] (DEF) -- (X) -- (GHI);
  \draw[->]          (X) -| (ABC); % -| ... "first horizontal, then vertical"
  \draw[->]          (X) -| (KLM);

  % Decorations
  \draw[crossout]  ([yshift=1ex]ABC.north west) -- ([yshift=-1ex]ABC.south east);
  \draw[crossout]  ([yshift=1ex]ABC.north east) -- ([yshift=-1ex]ABC.south west);
  \draw[strikeout] ([yshift= 0.5ex]KLM.west) -- ([yshift= 0.5ex]KLM.east);
  \draw[strikeout] ([yshift=-0.5ex]KLM.west) -- ([yshift=-0.5ex]KLM.east);
\end{tikzpicture}
\end{document}

答案4

一个pstricks办法:

  \documentclass[border=26pt, svgnames]{standalone}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}%
\usepackage{ pst-tree}
\usepackage{auto-pst-pdf}

\newcommand*{\treebox}[1]{\setlength{\fboxrule}{0.8pt}\fcolorbox{SteelBlue}{LightSteelBlue!30}{\makebox[1.6cm]{\centering \color{DarkBlue} #1\strut}}}

\begin{document}

\psset{treesep=0.8cm, nodesepB=0pt, levelsep=2.5cm, arrowinset=0.1, linejoin=1}
\renewcommand{\psedge}{\ncangle[angleA=-90, angleB=90, arm=0.8cm, arrows=->, linecolor=SteelBlue]}
\pstree{\Tr{\treebox{d e f}}}{\Tr[name=abc]{\treebox{a b c}} \Tr{\treebox{g h i}} \Tr[name=klm]{\treebox{k l m}}}
\psset{linecolor=Tomato, origin={abc}}
\psline(1;40)(-1;40)\psline(1;-40)(-1;-40)
\psset{linecolor=RoyalBlue,, origin={klm}}
\psline(-1,0.12 )(1,0.12)\psline(-1,-0.12)(1,-0.12)

\end{document} 

在此处输入图片描述

相关内容