在中间改变“兄弟距离”和“级别距离”

在中间改变“兄弟距离”和“级别距离”

我有以下决策树,我想将其放在一页中。输出如下所示。MWE 如下。

请注意,当树增长到第四个底部节点时,doses given它有 4 个子节点。这占用了太多空间,并被强制移出页面。另一个问题是path 7节点框与节点的框重叠age……(它们不一样!只是几何相加的问题)。

我还有很多空白区域想要填补。从这个意义上讲,最好有 90 度节点,而不是有角度的节点。

mwe 示例

% Scenario tree
% Author: Rasmus Pank Roulund
\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{shapes}
\usepackage{amsmath}
\usepackage{xspace}
\begin{document}
\begin{tikzpicture}[
    grow=down,
    level 1/.style={sibling distance=6.3cm,level distance=3.5cm},
    edge from parent/.style={very thick,draw=black, %blue!40!black!60
        shorten >=5pt, shorten <=5pt},
    %edge from parent path={(\tikzparentnode.east) -- (\tikzchildnode.west)},
    kant/.style={text width=2cm, text centered, sloped},
    every node/.style={text ragged, inner sep=2mm},
    punkt/.style={rectangle, rounded corners, top color=white,
    bottom color=white, draw=black, very
    thick }
    ]
\node[punkt, text width=5.5em] {Health at infection}
    %Lower part lv1
    child {
        node[punkt] [rectangle split, rectangle split, rectangle split parts=3,
         text ragged] {
            \textbf{Path 6}
            \nodepart{second}
            $\mathcal{P}(\text{carriage}) = (0, 0)$
            \nodepart{third}
            $\mathcal{P}(\text{invasive}) = (0, 0)$
        }
        edge from parent
            node[kant, above] {Recovered}
    }
    %Upper part, lv1
    child {
        node[punkt] {previous infection?} 
        %child 1 %% "yes" child
        child {
            node [punkt,rectangle split, rectangle split, rectangle split parts=3] {
                \textbf{Path 7}
                \nodepart{second}
                $\mathcal{P}(\text{carriage}) = (0, 0)$
                \nodepart{third}
                $\mathcal{P}(\text{invasive}) = (0, 0)$
            }
            edge from parent
            node[below, kant] {Yes} % node[below, kant,  pos=.6] {Yes}
        }
        %child 2
        child {
            node [punkt]{is vaccinated?}
            child{
                node[punkt]{age}
                child{
                    node [punkt,rectangle split, rectangle split, rectangle split parts=3] {
                        \textbf{Path 7}
                        \nodepart{second}
                        $\mathcal{P}(\text{carriage}) = (0, 0)$
                        \nodepart{third}
                        $\mathcal{P}(\text{invasive}) = (0, 0)$
                    }
                    edge from parent
                        node[kant, above]{ \textgreater{1825}} 
                }
                child{
                    node [punkt,rectangle split, rectangle split, rectangle split parts=3] {
                        \textbf{Path 7}
                        \nodepart{second}
                        $\mathcal{P}(\text{carriage}) = (0, 0)$
                        \nodepart{third}
                        $\mathcal{P}(\text{invasive}) = (0, 0)$
                    }
                    edge from parent
                        node[kant, above]{ \textless{1825}} 
                }
                edge from parent
                    node[kant, above]{No}
            } 
            child{
                node[punkt]{Doses Given}
                child{
                    node [punkt,rectangle split, rectangle split, rectangle split parts=3] {
                        \textbf{Path 7}
                        \nodepart{second}
                        $\mathcal{P}(\text{carriage}) = (0, 0)$
                        \nodepart{third}
                        $\mathcal{P}(\text{invasive}) = (0, 0)$
                    }
                    edge from parent
                        node[kant, above]{1} 
                }
                child{
                    node [punkt,rectangle split, rectangle split, rectangle split parts=3] {
                        \textbf{Path 7}
                        \nodepart{second}
                        $\mathcal{P}(\text{carriage}) = (0, 0)$
                        \nodepart{third}
                        $\mathcal{P}(\text{invasive}) = (0, 0)$
                    }
                    edge from parent
                        node[kant, above]{2} 
                }
                child{
                    node [punkt,rectangle split, rectangle split, rectangle split parts=3] {
                        \textbf{Path 7}
                        \nodepart{second}
                        $\mathcal{P}(\text{carriage}) = (0, 0)$
                        \nodepart{third}
                        $\mathcal{P}(\text{invasive}) = (0, 0)$
                    }
                    edge from parent
                        node[kant, above]{3} 
                }
                child{
                    node [punkt,rectangle split, rectangle split, rectangle split parts=3] {
                        \textbf{Path 7}
                        \nodepart{second}
                        $\mathcal{P}(\text{carriage}) = (0, 0)$
                        \nodepart{third}
                        $\mathcal{P}(\text{invasive}) = (0, 0)$
                    }
                    edge from parent
                        node[kant, above]{4} 
                }
                edge from parent
                    node[kant, above]{Yes}
            } 
            edge from parent
                node[kant, above] {No}
        }
        edge from parent{
            node[kant, above] {From Susceptible}}
    };
\end{tikzpicture}
\end{document}

寻找类似于这里所展示的树的东西:http://texample.net/tikz/examples/fault-tree/

答案1

我搞明白了。虽然我已经grow=down在“全局”级别定义了,但我可以在节点级别重新定义。现在我有

在此处输入图片描述

使用代码

% Scenario tree
% Author: Rasmus Pank Roulund
\documentclass[tikz]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes}
\usepackage{amsmath}
\usepackage{xspace}
\begin{document}
\begin{tikzpicture}[
    grow=down,
    level 1/.style={sibling distance=6.3cm,level distance=3.5cm},
    edge from parent/.style={very thick,draw=black, %blue!40!black!60
        shorten >=5pt, shorten <=5pt},
    %edge from parent path={(\tikzparentnode.east) -- (\tikzchildnode.west)},
    kant/.style={text centered, sloped}, %text width=2cm
    every node/.style={text ragged, inner sep=2mm},
    punkt/.style={rectangle, rounded corners, top color=white, bottom color=white, draw=black, very thick }
    ]
\node[punkt, text width=5.5em] {Health at infection}
    %Lower part lv1
    child {
        node[punkt] [rectangle split, rectangle split, rectangle split parts=3,
         text ragged] {
            \textbf{Path 6}
            \nodepart{second}
            $\mathcal{P}(\text{carriage}) = (0, 0)$
            \nodepart{third}
            $\mathcal{P}(\text{invasive}) = (0, 0)$
        }
        edge from parent
            node[kant, above] {recovered}
    }
    %Upper part, lv1
    child {
        node[punkt] {previous infection?} 
        %child 1 %% "yes" child
        child {
            node [punkt,rectangle split, rectangle split, rectangle split parts=3] {
                \textbf{Path 7}
                \nodepart{second}
                $\mathcal{P}(\text{carriage}) = (0, 0)$
                \nodepart{third}
                $\mathcal{P}(\text{invasive}) = (0, 0)$
            }
            edge from parent
            node[below, kant] {Yes} % node[below, kant,  pos=.6] {Yes}
        }
        %child 2
        child {
            node [punkt]{is vaccinated?}[grow=right]
            child{
                node[punkt]{Doses Given}[grow=down]
                child{
                    node [punkt,rectangle split, rectangle split, rectangle split parts=3] {
                        \textbf{Path 7}
                        \nodepart{second}
                        $\mathcal{P}(\text{carriage}) = (0, 0)$
                        \nodepart{third}
                        $\mathcal{P}(\text{invasive}) = (0, 0)$
                    }
                    edge from parent
                        node[kant, above]{1} 
                }
                child{
                    node [punkt,rectangle split, rectangle split, rectangle split parts=3] {
                        \textbf{Path 7}
                        \nodepart{second}
                        $\mathcal{P}(\text{carriage}) = (0, 0)$
                        \nodepart{third}
                        $\mathcal{P}(\text{invasive}) = (0, 0)$
                    }
                    edge from parent
                        node[kant, above]{2} 
                }
                child{
                    node [punkt,rectangle split, rectangle split, rectangle split parts=3] {
                        \textbf{Path 7}
                        \nodepart{second}
                        $\mathcal{P}(\text{carriage}) = (0, 0)$
                        \nodepart{third}
                        $\mathcal{P}(\text{invasive}) = (0, 0)$
                    }
                    edge from parent
                        node[kant, above]{3} 
                }
                child{
                    node [punkt,rectangle split, rectangle split, rectangle split parts=3] {
                        \textbf{Path 7}
                        \nodepart{second}
                        $\mathcal{P}(\text{carriage}) = (0, 0)$
                        \nodepart{third}
                        $\mathcal{P}(\text{invasive}) = (0, 0)$
                    }
                    edge from parent
                        node[kant, above]{4} 
                }
                edge from parent
                    node[kant, above]{Yes}
            }
            child{
                node[punkt]{age}
                child{
                    node [punkt,rectangle split, rectangle split, rectangle split parts=3] {
                        \textbf{Path 7}
                        \nodepart{second}
                        $\mathcal{P}(\text{carriage}) = (0, 0)$
                        \nodepart{third}
                        $\mathcal{P}(\text{invasive}) = (0, 0)$
                    }
                    edge from parent
                        node[kant, above]{ \textgreater{1825}} 
                }
                child{
                    node [punkt,rectangle split, rectangle split, rectangle split parts=3] {
                        \textbf{Path 7}
                        \nodepart{second}
                        $\mathcal{P}(\text{carriage}) = (0, 0)$
                        \nodepart{third}
                        $\mathcal{P}(\text{invasive}) = (0, 0)$
                    }
                    edge from parent
                        node[kant, above]{ \textless{1825}} 
                }
                edge from parent
                    node[kant, above]{No}
            }             
            edge from parent
                node[kant, above] {No}
        }
        edge from parent{
            node[kant, above] {From Susceptible}}
    };
\end{tikzpicture}
\end{document}

答案2

我遇到了同样的问题,并根据 masfenix 的解决方案代码找到了解决方案。但是,我认为我的解决方案更简单。因此,我将添加它,对于那些 2 年后像我一样在 Google 上搜索同样内容的人:

masfenix 在其 tikzpicture 中定义了以下全局变量: level 1/.style={sibling distance=6.3cm,level distance=3.5cm},

所以,我想,如果我对每个级别尝试同样的事情,那么我就可以全局设置每个级别的距离?

瞧,添加

level 2/.style={sibling distance=xy cm,level distance=xy cm},
level 3/.style={sibling distance=xy cm,level distance=xy cm},
and so on...

按照我的要求操作。成功!

相关内容