步骤 1:更改sibling distance。

步骤 1:更改sibling distance。

我需要您的帮助。
我想用 Tikz 在概念图的节点中添加段落,也就是多行文本。
我在文本方面遇到了问题,节点重叠了。
代码如下:

\documentclass{article}  
\usepackage{tikz}  
%  
\usetikzlibrary{mindmap}  
\usetikzlibrary{trees}

\begin{document}  
\begin{center}
\begin{tikzpicture}[edge from parent fork down,edge from parent/.style={black,thick,draw},every node/.style={rectangle,draw,rounded corners}]
\node at (0,0) {
\begin{tabular}{m{30mm}}
Text very long Text very long Text very long Text very long Text very long Text very long Text very long Text very long Text very long\\
Text very long Text very long Text very long Text very long Text very long Text very long Text very long\\
\end{tabular}
}
child {node {text}}
child {node {text}
child {node {\begin{tabular}{m{30mm}}
Text very long Text very long Text very long Text very long Text very long Text very long Text very long Text very long Text very long\\
Text very long Text very long Text very long Text very long Text very long Text very long Text very long\\
\end{tabular}}}
child {node {\begin{tabular}{m{30mm}}
Text very long Text very long Text very long Text very long Text very long Text very long Text very long Text very long Text very long\\
Text very long Text very long Text very long Text very long Text very long Text very long Text very long\\
\end{tabular}}}
};
\end{tikzpicture}
\end{center}

\end{document}

答案1

树节点的放置取决于

  • 钥匙level distance
  • sibling distance(默认值为15mm:),
  • 钥匙growth parent anchor,以及
  • anchor孩子们常用的钥匙。

增长路径取决于: - 节点的位置, - 关键parent anchor,和 -child anchor关键(均为默认值:)center

并不child anchor重要,因为所选增长路径的最后一个路径算子是-|。可以将其设置为north

路径是:

(\tikzparentnode\tikzparentanchor) -- +(0pt,-.5\tikzleveldistance)
                                   -|  (\tikzchildnode\tikzchildanchor)

步骤 1:更改sibling distance

在这个例子中,我们可以将锚点设置为east和,west但这只对两个节点起作用,并阻止我们做以后需要做的事情。

因此sibling distance是手动设置的。

步骤 2 和 3:更改growth parent anchor并设置所有子节点为anchor=north

设置在和孩子们的平常level distance之间。growth parent anchoranchor

设置growth parent anchor=south将从边界anchor=northlevel distance边界,而不是从中心到中心。

步骤 3:改变parent anchor

增长路径始于(<parent node>),并到达低于一半水平距离的点(<parent node>),然后“水平垂直”(-|)延伸至(<child node>)

为了计算中间点的.center锚点<parent node>被使用,但是实际线连接到 的边界<parent node>(巧合的是,这也是.south锚点)!
这就是为什么对于大节点(具体来说:一半高度大于一半水平距离的节点)来说,尽管使用了相对坐标,线还是会进入节点内部。

parent anchor这就是通过键设置起始节点锚点的原因south

代码

\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{mindmap}

\begin{document}
\begin{tikzpicture}[
    edge from parent fork down,
    edge from parent/.style={black,thick,draw},
    every node/.style={rectangle,draw,rounded corners},
    every child node/.style={anchor=north}, % due to lack of a 'growth child anchor' style
                                            % the .north anchor is selected manually
                                            % this affects the placement
    par node/.style={
        text width=#1,
        align=center,
    },
    par node/.default=30mm,
    parent anchor=south,
    growth parent anchor=south,
]

\node[par node] (p) at (0,0) {
        Text very long Text very long Text very long Text very long Text very long Text very long Text very long Text very long Text very long\\
        Text very long Text very long Text very long Text very long Text very long Text very long Text very long
    }
    child {node {text}}
    child {node {text}
        [sibling distance=40mm]
        child {node[par node] {
                Text very long Text very long Text very long Text very long Text very long Text very long Text very long Text very long Text very long\\
                Text very long Text very long Text very long Text very long Text very long Text very long Text very long
            }
        }
        child {node[par node] {
                Text very long Text very long Text very long Text very long Text very long Text very long Text very long Text very long Text very long\\
                Text very long Text very long Text very long Text very long Text very long Text very long Text very long
            }
        }
    };
\end{tikzpicture}
\end{document}

输出

在此处输入图片描述

相关内容