这就是我所拥有的
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{trees}
\begin{document}
\begin{center}
\begin{tikzpicture}[level 1/.style={sibling distance=5cm},level 2/.style={sibling distance=4.0cm}]
\node {1}[edge from parent fork down]
child { node {2}}
child { node {3}
child {node{4} }
child {node{5}}
}
;
\end{tikzpicture}
\end{center}
\end{document}
答案1
为了进行比较,你可以使用以下方法执行此操作forest
:
\documentclass{article}
\usepackage[edges]{forest}
\begin{document}
\begin{forest}
for tree={forked edge, edge=->, draw, circle, minimum size=8mm, l sep=5mm}
[1, s sep=5cm
[2]
[3, s sep=4cm
[4, s sep=3cm
[6, s sep=1cm
[9][10][11]
]
[7]
[8, s sep=2cm
[12][13]
]
]
[5]
]
]
\end{forest}
\end{document}
答案2
你只需要嵌套你的child
:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{trees}
\begin{document}
\begin{center}
\begin{tikzpicture}[level 1/.style={sibling distance=5cm},
level 2/.style={sibling distance=4.0cm},
level 3/.style={sibling distance=2.0cm},
level 4/.style={sibling distance=1.0cm}]
\node {1}[edge from parent fork down]
child { node {2}}
child { node {3}
child {node{4}
child {node{6}
child {node{9}}
child {node{10}}
child {node{11}}}
child {node{7}}
child {node{8}
child {node{12}}
child {node{13}}}}
child {node{5}}
}
;
\end{tikzpicture}
\end{center}
\end{document}
如果你确实想要带圆圈的数字,请在tikzpicture
的选项中添加
every node/.style={draw, circle},
答案3
这是基于 Sandy G 的回答。我不知道您使用的是 A4 还是 US letter。可能是后者,但我认为前者更窄。
如果您使用forest
,那么类似于您的树的东西就很合适。它不完全是您的树,因为当单词变得不熟悉时,我失去了耐心输入内容,而是开始编造东西。
请注意,切换到有帮助的原因forest
是该包默认生成更紧凑的树(fit=tight
)。
\begin{forest}
% ateb: https://tex.stackexchange.com/a/707154/ addaswyd o ateb Sandy G: https://tex.stackexchange.com/a/706800/
forked edges,
for tree={
edge+=->,
draw,
font=\sffamily,
},
where={>Ow+P{n children}{isodd(#1)}}{%
delay={for n=2{calign with current edge}}
}{},
[Fluids
[Ideal Fluids]
[Real Fluids
[Non-Newtonian Fluids
[Time-Independant Fluids
[Vouch-saving Vanilla][Soliciting Sourdough][Advocating Avocado]
]
[Timeless Thyme]
[Time-Dependant Fluids
[Peppermint][Spearmint]
]
]
[Newtonian Fluids]
]
]
\end{forest}
完整代码:
\documentclass[a4paper]{article}
\usepackage[showframe]{geometry}
% ateb: https://tex.stackexchange.com/a/707154/ addaswyd o ateb Sandy G: https://tex.stackexchange.com/a/706800/
\usepackage[edges]{forest}
\begin{document}
\noindent
\begin{forest}
% ateb: https://tex.stackexchange.com/a/707154/ addaswyd o ateb Sandy G: https://tex.stackexchange.com/a/706800/
forked edges,
for tree={
edge+=->,
draw,
font=\sffamily,
},
where={>Ow+P{n children}{isodd(#1)}}{%
delay={for n=2{calign with current edge}}
}{},
[Fluids
[Ideal Fluids]
[Real Fluids
[Non-Newtonian Fluids
[Time-Independant Fluids
[Vouch-saving Vanilla][Soliciting Sourdough][Advocating Avocado]
]
[Timeless Thyme]
[Time-Dependant Fluids
[Peppermint][Spearmint]
]
]
[Newtonian Fluids]
]
]
\end{forest}
\end{document}
如果这还不够,我建议sidewaysfigure
从rotating
包中使用或在节点中允许换行。
\begin{forest}
% ateb: https://tex.stackexchange.com/a/707154/ addaswyd o ateb Sandy G: https://tex.stackexchange.com/a/706800/
forked edges,
for tree={
edge+=->,
draw,
font=\sffamily,
align=center,
},
where={>Ow+P{n children}{isodd(#1)}}{%
delay={for n=2{calign with current edge}}
}{},
[Fluids
[Ideal Fluids]
[Real Fluids
[Non-Newtonian Fluids
[Time-Independant\\Fluids
[Vouch-saving\\Vanilla][Soliciting\\Sourdough][Advocating\\Avocado]
]
[Timeless\\Thyme]
[Time-Dependant\\Fluids
[Peppermint][Spearmint]
]
]
[Newtonian Fluids]
]
]
\end{forest}
更好的做法是避免重复信息。树的顶部表示这些都是流体,所以为什么要重复自己?删除多余的部分Fluids
可能会让你的图表更清晰,即使它不会减少太多的宽度。
或者,如果你想要更具冒险精神,你甚至可以转变顽固节点,尽管我只建议在适当的情况下使用此方法(我怀疑这不属于其中之一)。
\begin{forest}
% ateb: https://tex.stackexchange.com/a/707154/ addaswyd o ateb Sandy G: https://tex.stackexchange.com/a/706800/
forked edges,
for tree={
edge+=->,
draw,
font=\sffamily,
},
where={>Ow+P{n children}{isodd(#1)}}{%
delay={for n=2{calign with current edge}}
}{},
before typesetting nodes={%
tempcounta/.max={>O{level}}{tree},
where={> OR= {level}{tempcounta}}{rotate=-90,anchor=parent}{},
},
[Fluids
[Ideal]
[Real
[Non-Newtonian
[Time-Independent
[Vouch-saving Vanilla][Soliciting Sourdough][Advocating Avocado]
]
[Timeless Thyme]
[Time-Dependant
[Peppermint][Spearmint]
]
]
[Newtonian]
]
]
\end{forest}