树形图工具

树形图工具

我想制作一个看起来像树形图的简单方案(结构如下或者)。问题是,我尝试过的所有软件包都无法在节点信息很少的情况下生成漂亮的二叉树。我的树不是二叉树,我需要在每个节点上放一些单词,那么您可以推荐我尝试哪些工具来实现这一点?

答案1

我认为 TikZ 可以毫无问题地做到这一点,而且不需要库。如果您想自动更改某些内容,可以添加一些参数。您可以使用下一种方法进行扩展,而不会出现问题。

\documentclass[11pt]{scrartcl}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}[every node/.style = {shape          = rectangle,
                                         rounded corners,
                                         fill           = blue!40!white,
                                         minimum width  = 3cm,
                                         minimum height = 1.5cm,
                                         align          = center,
                                         text           = white},
                   blue edge/.style  = { -,
                                         ultra thick,
                                         blue!40!white,
                                         shorten >= 4pt}]

% the nodes : possible  \newcommand*\dx{5} \newcommand*\dy{2}
\node(0;0) at (0,0) {Eukaryotes};
  \node(1;2)  at (5, 4) {Unikonts};   
  \node(1;1)  at (5, 2) {Chromalveolates}; 
  \node(1;0)  at (5, 0) {Excavates}; 
  \node(1;-1) at (5,-2) {Rhizaria}; 
  \node(1;-2) at (5,-4) {Plantae\\
                   (Archeplastida)};
     \node(2;1)  at (10,-2) {Conifers};
     \node(2;0)  at (10,-4) {Gnetales};
     \node(2;-1) at (10,-6) {Angiosperms};

% edges 
\foreach \j in {-2,...,2}
  { \draw[blue edge] (0;0.east) -- (1;\j.west); }
\foreach \j in {-1,...,1}
  { \draw[blue edge] (1;-2.east) -- (2;\j.west);}                  
\end{tikzpicture}
\end{document} 

在此处输入图片描述

如果要用参数修改位置:

\documentclass[11pt]{scrartcl}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}[every node/.style = {shape          = rectangle,
                                         rounded corners,
                                         fill           = blue!40!white,
                                         minimum width  = 3cm,
                                         minimum height = 1.5cm,
                                         align          = center,
                                         text           = white},
                   blue edge/.style  = { -,
                                         ultra thick,
                                         blue!40!white,
                                         shorten >= 4pt}] 

\newcommand*\dx{5} \newcommand*\dy{2} 
% nodes 
\node(0;0) at (0,0) {Eukaryotes};
  \node(1;2)   at (\dx, 2*\dy) {Unikonts};   
  \node(1;1)   at (\dx, \dy)   {Chromalveolates}; 
  \node(1;0)   at (\dx, 0)     {Excavates}; 
  \node(1;-1)  at (\dx,-\dy)   {Rhizaria}; 
  \node(1;-2)  at (\dx,-2*\dy) {Plantae\\
                               (Archeplastida)};
     \node(2;1)  at (2*\dx,-\dy)   {Conifers};
     \node(2;0)  at (2*\dx,-2*\dy) {Gnetales};
     \node(2;-1) at (2*\dx,-3*\dy) {Angiosperms};

% edges     
\foreach \j in {-2,...,2}
  { \draw[blue edge] (0;0.east) -- (1;\j.west); }
\foreach \j in {-1,...,1}
  { \draw[blue edge] (1;-2.east) -- (2;\j.west);}                  
\end{tikzpicture}
\end{document} 

答案2

一个没有坐标的示例。使用xelatex或运行它latex->dvips->ps2pdf

\documentclass{article}
\usepackage{pst-tree,array}    
\begin{document}
\def\PSB#1{\pspicture(3,1.5)\psTextFrame[shadow,fillcolor=red!30,
  fillstyle=solid,linecolor=blue,framearc=0.3](0,0)(3,1.5){%
    \shortstack{#1}}\endpspicture}

\pstree[treemode=R,levelsep=2cm]{\Tr[ref=rc]{\PSB{Eukaryotes}}}{%
  \Tr[ref=lc]{\PSB{Unikonts}}   
  \Tr[ref=lc]{\PSB{Chromalveolates}} 
  \Tr[ref=lc]{\PSB{Excavates}} 
  \Tr[ref=lc]{\PSB{Rhizaria}}
  \pstree[treemode=R,levelsep=4.5cm]{\Tr[ref=lc]{\PSB{Plantae\\(Archeplastida)}%
           \pnode(0,0.75){Dummy}{}}}{\def\pspred{Dummy}%
     \Tr[ref=lc]{\PSB{Conifers}}\def\pspred{Dummy}%
     \Tr[ref=lc]{\PSB{Gnetales}}\def\pspred{Dummy}%
     \Tr[ref=lc]{\PSB{Angiosperms}}%
  }}

\end{document} 

在此处输入图片描述

相关内容