嗨,这是我第一次提问。最近,我被要求绘制一棵深度最多为 10 且有 120 个叶子的超大二叉树。我尝试将树逆时针旋转 90 度。但是,它仍然太大,LaTeX 无法在一页中显示它。我想问一个绘制大树的解决方案。
以下是我的代码。
\documentclass{article}
\usepackage[margin=1in,includefoot]{geometry}
\usepackage{algorithm}
\usepackage{algpseudocode}
\usepackage{graphicx}
\usepackage{amsmath}
\newgeometry{left=0cm,bottom=1in}
\section*{Problem 4}\label{sec:q4}
\subsection*{(a).}\label{sec:q4a}
\begin{forest}
for tree={
grow=0,%tree direction
parent anchor=east,child anchor=west, % edge anchors
edge={line cap=round},outer sep=+1pt, % edge/node connection
rounded corners,minimum width=1mm,minimum height=1mm, % node shape
l sep=1mm % level distance
}
[a1:a5
[a2:a5,edge label={node[midway,fill=white]{$\leq$}}
[a3:a5,edge label={node[midway,fill=white]{$\leq$}}
[a4:a5,edge label={node[midway,fill=white]{$\leq$}}
[a1:a4,edge label={node[midway,fill=white]{$\leq$}}
[a2:a4,edge label={node[midway,fill=white]{$\leq$}}
[a3:a4,edge label={node[midway,fill=white]{$\leq$}}
[a1:a3,edge label={node[midway,fill=white]{$\leq$}}
[a2:a3,edge label={node[midway,fill=white]{$\leq$}}
[a1:a2,edge label={node[midway,fill=white]{$\leq$}}
[12345,edge label={node[midway,fill=white]{$\leq$}}]
[21345,edge label={node[midway,fill=white]{$>$}}]]
[13245,edge label={node[midway,fill=white]{$>$}}]]
[a2:a3,edge label={node[midway,fill=white]{$>$}}
[23145,edge label={node[midway,fill=white]{$\leq$}}]
[a2:a1,edge label={node[midway,fill=white]{$>$}}
[32145,edge label={node[midway,fill=white]{$\leq$}}]
[31245,edge label={node[midway,fill=white]{$>$}}]]]]
[a1:a2,edge label={node[midway,fill=white]{$>$}}
[12435,edge label={node[midway,fill=white]{$\leq$}}]
[21435,edge label={node[midway,fill=white]{$>$}}]]]
[a3:a4,edge label={node[midway,fill=white]{$>$}}
[a1:a3,edge label={node[midway,fill=white]{$\leq$}}
[13425,edge label={node[midway,fill=white]{$\leq$}}]
[31425,edge label={node[midway,fill=white]{$>$}}]]
[a1:a3,edge label={node[midway,fill=white]{$>$}}
[14325,edge label={node[midway,fill=white]{$\leq$}}]
[14235,edge label={node[midway,fill=white]{$>$}}]]]]
[a2:a4,edge label={node[midway,fill=white]{$>$}}
[a3:a4,edge label={node[midway,fill=white]{$\leq$}}
[a2:a3,edge label={node[midway,fill=white]{$\leq$}}
[23415,edge label={node[midway,fill=white]{$\leq$}}]
[32415,edge label={node[midway,fill=white]{$>$}}]]
[a3:a1,edge label={node[midway,fill=white]{$>$}}
[24315,edge label={node[midway,fill=white]{$\leq$}}]
[24135,edge label={node[midway,fill=white]{$>$}}]]]
[a3:a4,edge label={node[midway,fill=white]{$\leq$}}
[a2:a1,edge label={node[midway,fill=white]{$\leq$}}
[34215,edge label={node[midway,fill=white]{$\leq$}}]
[34125,edge label={node[midway,fill=white]{$>$}}]]
[a2:a1,edge label={node[midway,fill=white]{$>$}}
[a3:a1,edge label={node[midway,fill=white]{$\leq$}}
[a2:a3,edge label={node[midway,fill=white]{$\leq$}}
[42315,edge label={node[midway,fill=white]{$\leq$}}]
[43215,edge label={node[midway,fill=white]{$>$}}]]
[42135,edge label={node[midway,fill=white]{$>$}}]]
[a3:a1,edge label={node[midway,fill=white]{$>$}}
[43125,edge label={node[midway,fill=white]{$\leq$}}]
[a3:a2,edge label={node[midway,fill=white]{$>$}}
[41325,edge label={node[midway,fill=white]{$\leq$}}]
[41235,edge label={node[midway,fill=white]{$>$}}]]]]]]]
[12354,edge label={node[midway,fill=white]{$<$}}]
]
[a4:a5,edge label={node[midway,fill=white]{$>$}}
[12453,edge label={node[midway,fill=white]{$\leq$}}]
[12543,edge label={node[midway,fill=white]{$<$}}]
]]
[a3:a5,edge label={node[midway,fill=white]{$<$}}
[a4:a5,edge label={node[midway,fill=white]{$\leq$}}
[13452,edge label={node[midway,fill=white]{$\leq$}}]
[13542,edge label={node[midway,fill=white]{$<$}}]]
[a4:a5,edge label={node[midway,fill=white]{$>$}}
[14532,edge label={node[midway,fill=white]{$\leq$}}]
[15342,edge label={node[midway,fill=white]{$<$}}]]]]
[a2:a5,edge label={node[midway,fill=white]{$>$}}
[a3:a5,edge label={node[midway,fill=white]{$\leq$}}
[a4:a5,edge label={node[midway,fill=white]{$\leq$}}
[23451,edge label={node[midway,fill=white]{$\leq$}}]
[23541,edge label={node[midway,fill=white]{$>$}}]
]
[a4:a5,edge label={node[midway,fill=white]{$>$}}
[24531,edge label={node[midway,fill=white]{$\leq$}}]
[25341,edge label={node[midway,fill=white]{$>$}}]
]]
[a3:a5,edge label={node[midway,fill=white]{$>$}}
[a4:a5,edge label={node[midway,fill=white]{$\leq$}}
[34521,edge label={node[midway,fill=white]{$\leq$}}]
[35241,edge label={node[midway,fill=white]{$>$}}]
]
[a4:a5,edge label={node[midway,fill=white]{$>$}}
[45231,edge label={node[midway,fill=white]{$\leq$}}]
[52341,edge label={node[midway,fill=white]{$>$}}]]]]]
\end{forest}
\end{document}
答案1
根据我的发现,即使你选择了forest
这个linguistics
选项,如果你减少兄弟姐妹之间的距离,它确实适合。
\documentclass{article}
\usepackage[margin=1in,includefoot]{geometry}
\usepackage[linguistics]{forest}
\begin{document}
\section*{Problem 4}\label{sec:q4}
\subsection*{(a).}\label{sec:q4a}
\begin{forest}
for tree={
grow=0,%tree direction
parent anchor=east,child anchor=west, % edge anchors
edge={line cap=round},outer sep=+1pt, % edge/node connection
rounded corners,minimum width=1mm,minimum height=1mm, % node shape
l sep=3mm, % level distance
s sep=0.5mm
}
[a1:a5
[a2:a5,edge label={node[midway,fill=white]{$\leq$}}
[a3:a5,edge label={node[midway,fill=white]{$\leq$}}
[a4:a5,edge label={node[midway,fill=white]{$\leq$}}
[a1:a4,edge label={node[midway,fill=white]{$\leq$}}
[a2:a4,edge label={node[midway,fill=white]{$\leq$}}
[a3:a4,edge label={node[midway,fill=white]{$\leq$}}
[a1:a3,edge label={node[midway,fill=white]{$\leq$}}
[a2:a3,edge label={node[midway,fill=white]{$\leq$}}
[a1:a2,edge label={node[midway,fill=white]{$\leq$}}
[12345,edge label={node[midway,fill=white]{$\leq$}}]
[21345,edge label={node[midway,fill=white]{$>$}}]]
[13245,edge label={node[midway,fill=white]{$>$}}]]
[a2:a3,edge label={node[midway,fill=white]{$>$}}
[23145,edge label={node[midway,fill=white]{$\leq$}}]
[a2:a1,edge label={node[midway,fill=white]{$>$}}
[32145,edge label={node[midway,fill=white]{$\leq$}}]
[31245,edge label={node[midway,fill=white]{$>$}}]]]]
[a1:a2,edge label={node[midway,fill=white]{$>$}}
[12435,edge label={node[midway,fill=white]{$\leq$}}]
[21435,edge label={node[midway,fill=white]{$>$}}]]]
[a3:a4,edge label={node[midway,fill=white]{$>$}}
[a1:a3,edge label={node[midway,fill=white]{$\leq$}}
[13425,edge label={node[midway,fill=white]{$\leq$}}]
[31425,edge label={node[midway,fill=white]{$>$}}]]
[a1:a3,edge label={node[midway,fill=white]{$>$}}
[14325,edge label={node[midway,fill=white]{$\leq$}}]
[14235,edge label={node[midway,fill=white]{$>$}}]]]]
[a2:a4,edge label={node[midway,fill=white]{$>$}}
[a3:a4,edge label={node[midway,fill=white]{$\leq$}}
[a2:a3,edge label={node[midway,fill=white]{$\leq$}}
[23415,edge label={node[midway,fill=white]{$\leq$}}]
[32415,edge label={node[midway,fill=white]{$>$}}]]
[a3:a1,edge label={node[midway,fill=white]{$>$}}
[24315,edge label={node[midway,fill=white]{$\leq$}}]
[24135,edge label={node[midway,fill=white]{$>$}}]]]
[a3:a4,edge label={node[midway,fill=white]{$\leq$}}
[a2:a1,edge label={node[midway,fill=white]{$\leq$}}
[34215,edge label={node[midway,fill=white]{$\leq$}}]
[34125,edge label={node[midway,fill=white]{$>$}}]]
[a2:a1,edge label={node[midway,fill=white]{$>$}}
[a3:a1,edge label={node[midway,fill=white]{$\leq$}}
[a2:a3,edge label={node[midway,fill=white]{$\leq$}}
[42315,edge label={node[midway,fill=white]{$\leq$}}]
[43215,edge label={node[midway,fill=white]{$>$}}]]
[42135,edge label={node[midway,fill=white]{$>$}}]]
[a3:a1,edge label={node[midway,fill=white]{$>$}}
[43125,edge label={node[midway,fill=white]{$\leq$}}]
[a3:a2,edge label={node[midway,fill=white]{$>$}}
[41325,edge label={node[midway,fill=white]{$\leq$}}]
[41235,edge label={node[midway,fill=white]{$>$}}]]]]]]]
[12354,edge label={node[midway,fill=white]{$<$}}]
]
[a4:a5,edge label={node[midway,fill=white]{$>$}}
[12453,edge label={node[midway,fill=white]{$\leq$}}]
[12543,edge label={node[midway,fill=white]{$<$}}]
]]
[a3:a5,edge label={node[midway,fill=white]{$<$}}
[a4:a5,edge label={node[midway,fill=white]{$\leq$}}
[13452,edge label={node[midway,fill=white]{$\leq$}}]
[13542,edge label={node[midway,fill=white]{$<$}}]]
[a4:a5,edge label={node[midway,fill=white]{$>$}}
[14532,edge label={node[midway,fill=white]{$\leq$}}]
[15342,edge label={node[midway,fill=white]{$<$}}]]]]
[a2:a5,edge label={node[midway,fill=white]{$>$}}
[a3:a5,edge label={node[midway,fill=white]{$\leq$}}
[a4:a5,edge label={node[midway,fill=white]{$\leq$}}
[23451,edge label={node[midway,fill=white]{$\leq$}}]
[23541,edge label={node[midway,fill=white]{$>$}}]
]
[a4:a5,edge label={node[midway,fill=white]{$>$}}
[24531,edge label={node[midway,fill=white]{$\leq$}}]
[25341,edge label={node[midway,fill=white]{$>$}}]
]]
[a3:a5,edge label={node[midway,fill=white]{$>$}}
[a4:a5,edge label={node[midway,fill=white]{$\leq$}}
[34521,edge label={node[midway,fill=white]{$\leq$}}]
[35241,edge label={node[midway,fill=white]{$>$}}]
]
[a4:a5,edge label={node[midway,fill=white]{$>$}}
[45231,edge label={node[midway,fill=white]{$\leq$}}]
[52341,edge label={node[midway,fill=white]{$>$}}]]]]]
\end{forest}
\end{document}