答案1
这应该可以帮助您开始使用forest
。edges
必须加载该库才能使用forked edge
。
\documentclass{article}
\usepackage{forest}
\useforestlibrary{edges}
\begin{document}
\begin{forest}
for tree={forked edge,
l sep=.5cm,
s sep=.5cm,
if n children=0{tier=leaf}{}
}
[$X_2<1$
[$X_1<1$
[$-1.80$]
[0.63]
]
[$X_2<2$
[$X_1<0$
[$-1.06$]
[0.21]
]
[2.49]
]
]
\end{forest}
\end{document}
答案2
将 Mathcha 编辑器与 TikZ 结合使用。
\documentclass[a4paper,12pt]{article}
\usepackage{tikz}
\begin{document}
\tikzset{every picture/.style={line width=0.75pt}} %set default line width to 0.75pt
\begin{tikzpicture}[x=0.75pt,y=0.75pt,yscale=-1,xscale=1]
%uncomment if require: \path (0,300); %set diagram left start at 0, and has height of 300
%Shape: Right Angle [id:dp48723979825727537]
\draw (271,108) -- (341,108) -- (341,178) ;
%Shape: Right Angle [id:dp539305270770597]
\draw (271,108) -- (201.8,108) -- (201.8,178) ;
%Shape: Right Angle [id:dp566680910502753]
\draw (198.11,178.27) -- (248,178.27) -- (248,220.46) ;
%Shape: Right Angle [id:dp7717469994484694]
\draw (198.11,178.27) -- (148.8,178.27) -- (148.8,220.46) ;
%Shape: Right Angle [id:dp8653500039706887]
\draw (339.56,177.27) -- (380.8,177.27) -- (380.8,197.8) ;
%Shape: Right Angle [id:dp8151753688592149]
\draw (339.56,177.27) -- (298.8,177.27) -- (298.8,197.8) ;
%Shape: Right Angle [id:dp13534020188934037]
\draw (302.75,198.27) -- (328.8,198.27) -- (328.8,219.8) ;
%Shape: Right Angle [id:dp4875428770343304]
\draw (302.75,198.27) -- (277,198.27) -- (277,219.8) ;
%Straight Lines [id:da01652899110190509]
\draw (271,99) -- (271,110) ;
% Text Node
\draw (246,78.86) node [anchor=north west][inner sep=0.75pt] {$X2< 1$};
% Text Node
\draw (176,157.86) node [anchor=north west][inner sep=0.75pt] {$X1< 1$};
% Text Node
\draw (316,158.86) node [anchor=north west][inner sep=0.75pt] {$X2< 2$};
% Text Node
\draw (273,181.4) node [anchor=north west][inner sep=0.75pt] {$X1< 0$};
% Text Node
\draw (124.8,221.4) node [anchor=north west][inner sep=0.75pt] [font=\small] {$-1.80$};
% Text Node
\draw (225.8,221.86) node [anchor=north west][inner sep=0.75pt] [font=\small] {$0.63$};
% Text Node
\draw (262.8,222.2) node [anchor=north west][inner sep=0.75pt] [font=\small] {$-1.06$};
% Text Node
\draw (312.8,223.2) node [anchor=north west][inner sep=0.75pt] [font=\small] {$0.21$};
% Text Node
\draw (364.8,201.2) node [anchor=north west][inner sep=0.75pt] [font=\small] {$2.49$};
\end{tikzpicture}
\end{document}