질문: 저는 제가 시작한 수형도를 완성하려고 노력해 왔습니다(그림 참조).
이것이 내가 가진 것입니다
\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
당신은 당신의 s를 중첩하면됩니다 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
트리와 비슷한 것이 적합합니다. 단어가 낯설어지면 내용을 입력하는 인내심을 잃고 대신 물건을 만들기 시작했기 때문에 그것은 당신의 나무가 아닙니다.
help 로 전환하는 이유는 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}