在树中绘制连续线

在树中绘制连续线

我用 Tikz 写了一棵树。代码如下

\documentclass[10pt]{article}
\usepackage{tikz}
\usetikzlibrary{trees}

\makeatletter
\date{}
\author{}

\makeatother
\begin{document}
\title{}
\maketitle
\begin{tikzpicture}
    [
        level 1/.style = { sibling distance = 8cm},
        level 2/.style = { sibling distance = 6cm},
        level 3/.style = { sibling distance = 4cm},
        level 4/.style = { sibling distance = 2cm},
        edge from parent fork down,
        inner sep =0cm
    ]
    \node {}
    child  {node {}
    child {node{}
                    child {node {}
                            child {node {Lamproie}}}}}
    child {node {}
            child {node {}
                    child {node {}
                            child {node {Anguille}}}}
            child {node {}
                    child {node{}
                            child {node {Dauphin}}
                            child {node {Gorille}}}
                    child {node {}
                            child {node {Crocodile}}
                            child {node {Aigle}}
                        }
                }
        }
    ;
\end{tikzpicture}
\end{document}

我想完全消除空节点处的间隙。我该怎么做?使用此代码获得的结果

答案1

比较forest简单。代码也更短更清晰:

\documentclass[margin=3mm]{standalone}
\usepackage[edges]{forest}

\begin{document}
\begin{forest}
delay={where content={}{shape=coordinate}{}}, % insert coordinates in empty node
where n children=0{tier=word}{},              % align nodes at bottom of tree
    for tree={
        forked edge,        % for forked edge
            s sep = 2mm,    % sibling distance
            l sep = 6mm,    % level distance
         fork sep = 3mm,    % distance from parent to branching point
              }
[
    [Lamproie]
    [
        [Anguille]
        [
            [
                [Dauphin]
                [Gorille]
            ] 
            [
                [Crocodil]
                [Aigle]
            ]
        ]
    ]
]
\end{forest}
\end{document}

在此处输入图片描述

相关内容