节点中有多行文本且某些文本上带有“X”的树

节点中有多行文本且某些文本上带有“X”的树

我想在 TeX 中复制我在 PowerPoint 中制作的树形图。与基本树相比,它更难的是终端节点的多行标签、某些终端节点标签上的 X 以及分支之间的“R.1/R.2”标签。

保留 PowerPoint 版本确实让我很烦恼,而且还要花一个月的时间去弄清楚。

感谢你的帮助。

兴趣图

答案1

这很容易做到forest。网站上有很多类似的树。我选择单独添加十字架,而不是forest直接将装饰添加到节点,因为这样可以更好地控制它们的大小。

\documentclass{article}
\usepackage[linguistics]{forest}
\usetikzlibrary{decorations,positioning}
\begin{document}
\begin{forest}for tree={l sep'=1cm,s sep'=1cm}
[Undertaking\\ART,name=Art
    [Unsuccesful,name=U
        [Spontaneous\\Conception\\(Only SC child)\\{[A]} ]
        [No Spontaneous\\Conception\\(no conception)\\{[B]},name=B]
    ]
    [Successful
        [Spontaneous\\Conception\\(very rare)\\{[C]},name=C ]
        [No Spontaneous\\Conception\\(only ART child)\\{[D]}]
    ]
]
\node[red,draw,cross out,minimum size=1cm] at (B) {};
\node[red,draw,cross out,minimum size=1cm] at (C) {};
\node[below=1cm of Art] {R.1};
\node[below=.5cm of U] {R.2};
\end{forest}
\end{document}

代码输出

如果您不喜欢该[linguistics]库使用的合并分支,请不要加载它,您将获得未合并的分支。在这种情况下,您需要将规范添加align=center到树中以允许节点中的换行符。

\documentclass{article}
\usepackage[]{forest}
\usetikzlibrary{decorations,positioning}
\begin{document}
\begin{forest}for tree={l sep'=1cm,s sep'=1cm,align=center}
[Undertaking\\ART,name=Art
    [Unsuccesful,name=U
        [Spontaneous\\Conception\\(Only SC child)\\{[A]} ]
        [No Spontaneous\\Conception\\(no conception)\\{[B]},name=B]
    ]
    [Successful
        [Spontaneous\\Conception\\(very rare)\\{[C]},name=C]
        [No Spontaneous\\Conception\\(only ART child)\\{[D]}]
    ]
]
\node[red,draw,cross out,minimum size=1cm] at (B) {};
\node[red,draw,cross out,minimum size=1cm] at (C) {};
\node[below=1cm of Art] {R.1};
\node[below=.5cm of U] {R.2};
\end{forest}
\end{document}

不含语言学库的输出

答案2

这是我自己的答案,在@Alan Munn 的帮助下找到的:

\documentclass{article}

    \usepackage{tikz}
      \usetikzlibrary{positioning}
      \usetikzlibrary{calc}
      \usetikzlibrary{trees}

\begin{document}

\begin{tikzpicture}[
    level 1/.style = {black, sibling distance = 8cm},
    level 2/.style = {black, sibling distance = 4cm},
    level distance = 3cm, % Increase the level distance  
  ]

  \node [align=center] (undertaking) {Undertaking \\ ART cycle}
  child {node [align=center] (succ) {Unsuccessful}
  child {node (A) [align=center] {Spontaneous \\ Conception \\ {\small (only SC child)} \\ {[A]}}}
  child {node (B) [align=center] {No Spontaneous \\ Conception \\ {\small (no conception)} \\ {[B]}}}
  }
  child {node (unsucc) {Successful}
  child {node (C) [align=center] {Spontaneous \\ Conception \\ {\small (only SC child)} \\ {[C]}}}
  child {node (D) [align=center] {No Spontaneous \\ Conception \\ {\small (no conception)} \\ {[D]}}}
  };

  \node [align=center, below=1cm of undertaking] {\bfseries R.1};
  \node [align=center, below=1cm of succ] {\bfseries R.2};
  \node [align=center, below=1cm of unsucc] {\bfseries R.2};
  \node[red,draw,cross out,minimum size=1.5cm] at (B) {};
  \node[red,draw,cross out,minimum size=1.5cm] at (C) {};
\end{tikzpicture}

\end{document}

在此处输入图片描述

相关内容