使用 tikzpicture 在图中添加一条线

使用 tikzpicture 在图中添加一条线

目前我的图表如下所示:

图表

使用以下代码:

\documentclass[a4paper]{article}
\usepackage{tikz}
\usetikzlibrary{trees}
\begin{document}
\begin{center}
\begin{tikzpicture}[level 1/.style={sibling distance=8cm},level 2/.style={sibling distance=2.50cm},level 3/.style={sibling distance=1.50cm}]
    \node {Statistical Testing}[edge from parent fork down]
            child { node {External Criteria}
                child { node {Rand Statistic}}
                child { node { Jaccard Coefficient}}
                child { node {Folkes and Mallows Index}}
                child { node {Hubert's $\Gamma$ statistic}}
                child { node {Normalized $\Gamma$ statistic}}
                  }
            child { node {Internal Criteria}
                child { node {Cophenetic Correlation Coefficient}}
                child { node {Hubert's $\Gamma$ statistic}}
                child { node {Normalized $\Gamma$ statistic}}
                  }
              ;
\end{tikzpicture}
\end{center}
\end{document}

我该如何在 Rand 和统计数据与所有其他数据之间添加一条线,以便有足够的空间来容纳该图表?

我尝试在两者之间添加 \ 但出现错误。

答案1

您可以设置text width节点的,然后会自动换行,这可以避免节点重叠。我个人会使用森林来绘制这样的图表。编辑:已修复overfull hboxes,非常感谢@cfr!!

\documentclass[a4paper]{article}
\usepackage[margin=1in,showframe]{geometry}
\usepackage{tikz}
\usetikzlibrary{trees}
\usepackage[edges]{forest} % for the second part of the anser
\begin{document}
\begin{center}
\begin{tikzpicture}[level 1/.style={sibling distance=7.3cm},
level 2/.style={sibling distance=1.8cm,text width=1.8cm,level distance=2.8cm},
level 3/.style={sibling distance=1.50cm}]
    \node {Statistical Testing}[edge from parent fork down]
            child { node {External Criteria}
                child { node {Rand Statistic}}
                child { node {\hskip0ptJaccard Coefficient}}
                child { node {Folkes and Mallows Index}}
                child { node {Hubert's $\Gamma$ statistic}}
                child { node {\hskip0ptNormalized $\Gamma$ statistic}}
                  }
            child { node {Internal Criteria}
                child { node {\hskip0ptCophenetic Correlation Coefficient}}
                child { node {Hubert's $\Gamma$ statistic}}
                child { node {\hskip0ptNormalized $\Gamma$ statistic}}
                  }
              ;
\end{tikzpicture}
\end{center}

\begin{center}
\begin{forest}
forked edges,
where level=2{text width=1.7cm}{},
for tree={s sep=1pt}
[Statistical Testing
            [External Criteria
                [Rand Statistic]
                [Jaccard Coefficient]
                [Folkes and Mallows Index]
                [Hubert's $\Gamma$ statistic]
                [\hskip0ptNormalized $\Gamma$ statistic]
                 ]
            [Internal Criteria
                [\hskip0ptCophenetic Correlation Coefficient]
                [Hubert's $\Gamma$ statistic]
                [\hskip0ptNormalized $\Gamma$ statistic]
                  ]
]                 
\end{forest}
\end{center}
\end{document}

在此处输入图片描述

相关内容