我想通过在父节点之间绘制一条边来清理我的树。接下来,我想让节点0
(现在是子节点)与编号节点相邻(即在“父”级别)。我该怎么做?我是否遗漏了一些简单的东西?谢谢!
\documentclass{article}
\usepackage{forest}
\begin{document}
\begin{forest}
for tree={circle, draw, l sep=20pt, s sep=5 mm}
[0, green
[0, green]
[1, red
[0, green]
[2, red
[0, green]
[3, red]
]
[3, red
[0, green]
[2, red]
]
]
[2, red
[0, green]
[1, red
[0, green]
[3, red]
]
[3, red
[0, green]
[1, red]
]
]
[3, red
[0, green]
[1, red
[0, green]
[2, red]
]
[2, red
[0, green]
[1, red]
]
]
]
\end{forest}
\end{document}
让每个0
节点与父节点处于同一级别并连接父节点。
也就是说,我希望它看起来像
0 ----- 0
/ \
0 --- 1 2 --- 0
/ \
2 3
答案1
这实际上不是一个答案,但如果您想要这类东西,它可以更好地澄清。
\documentclass{article}
\usepackage{forest}
\begin{document}
\begin{forest}
for tree={circle, draw, l sep=20pt, s sep=15mm}
[0, green,alias=L1
% [0, green]
[1, red,alias=L2
% [0, green]
[2, red,alias=L3
% [0, green]
[3, red]
]
[3, red,alias=L4
% [0, green]
[2, red]
]
]
[2, red,alias=L5
% [0, green]
[1, red,alias=L6
% [0, green]
[3, red]
]
[3, red,alias=L7
% [0, green]
[1, red]
]
]
[3, red,alias=L8
% [0, green]
[1, red,alias=L9
% [0, green]
[2, red]
]
[2, red,alias=L10
% [0, green]
[1, red]
]
]
]
\foreach \X in {1,...,10}
{\ifnum\X=1
\draw (L\X) -- ++ (-1.5cm,0) node[circle,left,draw,green]{0};
\else
\draw (L\X) -- ++ (-1cm,0) node[circle,left,draw,green]{0};
\fi}
\end{forest}
\end{document}
答案2
没有tikz-tree
解决方案:我只是尝试使用普通 Ti 复制你的图表钾是
\documentclass[tikz,margin=3mm]{standalone}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\node [circle,draw] (0c) at (0,0) {0};
\node [circle,draw] (1) at ($(0c)+(-120:1.5)$) {1};
\node [circle,draw] (2r) at ($(0c)+(-60:1.5)$) {2};
\node [circle,draw] (2l) at ($(1)+(-120:1.5)$) {2};
\node [circle,draw] (3) at ($(1)+(-60:1.5)$) {3};
\node [circle,draw] (0al) at ($(0c)+(-1.5,0)$) {0};
\node [circle,draw] (0bl) at ($(1)+(-1.5,0)$) {0};
\node [circle,draw] (0r) at ($(2r)+(1.5,0)$) {0};
\draw (0c)--(1)
(0c)--(2r)
(1)--(2l)
(1)--(3)
(0c)--(0al)
(1)--(0bl)
(2r)--(0r);
\end{tikzpicture}
\end{document}