答案1
我不知道利用forest
-library 的解决方案。但是,除了forest
-library,还可以直接使用positioning
-library 来实现所需的效果。代码如下...
\documentclass[tikz,border=5pt]{standalone}
\usetikzlibrary{positioning}
\def\X{.5}
\def\Y{1.5}
\begin{document}
\begin{tikzpicture}[%
every node/.style={circle,draw}
]
%
% the LHS branch
\node (A) at (0,0) {A};
\node[below left=\Y cm and \X cm of A] (B) {B};
\node[below left=\Y cm and \X cm of B] (E) {E};
\draw (A)--(B)--(E);
%
% the RHS branch
\node[below right=\Y cm and \X cm of A] (C) {C};
\node[below right=\Y cm and \X cm of C] (H) {H};
\draw (A)--(C)--(H);
\end{tikzpicture}
\end{document}
通过改变变量\X
和\Y
序言中的变量,可以简单地控制分支的角度。
答案2
在森林中,有很多选择,例如
\documentclass[tikz, border=5pt]{standalone}
\usepackage{forest}
\begin{document}
\begin{forest}
for tree={
circle,
draw
}
[A
[B
[E]
[,phantom]
[,phantom]
]
[C
[,phantom]
[,phantom]
[H]
]
]
\end{forest}
\begin{forest}
for tree={
circle,
draw
}
[A
[B,grow=-110
[E]
]
[C,grow=-70
[H]
]
]
\end{forest}
\end{document}
答案3
以下是实现它的一种方法:
\documentclass[12pt]{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}
% Nodes
\node[circle, draw=black] (a) at (0,0) {$A$};
\node[circle, draw=black, below left = of a] (b) {$B$};
\node[circle, draw=black, below right = of a] (c) {$C$};
\node[circle, draw=black, below left = of b] (d) {$D$};
\node[circle, draw=black, below right = of c] (e) {$E$};
% Draw
\draw[black] (a) -- (b);
\draw[black] (a) -- (c);
\draw[black] (b) -- (d);
\draw[black] (c) -- (e);
\end{tikzpicture}
\end{document}
希望能帮助到你。
罗曼