如何连接树上的 2 个水平节点?也就是说,我想将 z1 连接到 z2。但该线应继续延伸到 z2 的右侧和 z1 的左侧以显示连续性。对于 theta 1 和 theta 2 也是如此。
我当前的乳胶命令:
\begin{tikzpicture}[level distance=1.2cm,
level 1/.style={sibling distance=4cm},
level 2/.style={sibling distance=1cm}
]
\centering
\tikzstyle{every node}=[circle,draw]
\node (Root) [black] {$z_{1}$}
child {
node {$\theta_{1}$}
child { node {$\varphi_{1}$} edge from parent node[left,draw=none]{} }
child { node {$\varphi_{2}$} }
child { node {$\varphi_{3}$} }
};
\hspace*{4cm}\node (Root) [black] {$z_{2}$}
child {
node {$\theta_{2}$}
child { node {$\varphi_{1}$} }
child { node {$\varphi_{2}$} }
child { node {$\varphi_{3}$} }
child { node {$\varphi_{4}$} }
};
\end{tikzpicture}
答案1
我对你的代码做了一些改进:
- 使用
positioning
库的right=4cm of Root1
语法。 - 使用
\tikzset
而不是\tikzstyle
。 - 将节点重命名
(Root)
为(Root1)
并(Root2)
使用 连接它们\draw
。
\documentclass[tikz]{standalone}
\usetikzlibrary{positioning}
\tikzset{every node/.style = {circle,draw}}
\begin{document}
\begin{tikzpicture}[level distance=1.2cm,
level 1/.style={sibling distance=4cm},
level 2/.style={sibling distance=1cm}
]
\node (Root1) [black] {$z_{1}$}
child {
node {$\theta_{1}$}
child { node {$\varphi_{1}$} edge from parent node[left,draw=none]{} }
child { node {$\varphi_{2}$} }
child { node {$\varphi_{3}$} }
};
\node[right=4cm of Root1] (Root2) [black] {$z_{2}$}
child {
node {$\theta_{2}$}
child { node {$\varphi_{1}$} }
child { node {$\varphi_{2}$} }
child { node {$\varphi_{3}$} }
child { node {$\varphi_{4}$} }
};
\draw (Root1) -- (Root2);
\end{tikzpicture}
\end{document}