
TikZ를 사용하여 Branch-and-Bound 트리를 그리는 중인데 도움이 필요합니다.
내 코드는 다음과 같습니다.
\documentclass[
12pt,
oneside,
a4paper,
english,
french,
spanish,
brazil
]{abntex2}
\usepackage{graphicx}
\usepackage{float}
\usepackage{tikz}
\usetikzlibrary{calc, shapes}
\begin{document}
\begin{figure}[H]
\centering
\tikzset{thick,
tree node/.style = {align=center, inner sep=0pt, font = \scriptsize},
every label/.append style = {font=\scriptsize},
S/.style = {draw, circle, minimum size = 20mm, inner sep=0pt,
top color=white, bottom color=blue!20},
ENL/.style = {% edge node left
font=\footnotesize, left=1pt},
ENR/.style = {% edge node right
font=\footnotesize, right=1pt},
grow = down,
sibling distance = 2.8cm,
level distance = 3cm
}
\begin{tikzpicture}
\node [S, label= 2:Some text here] {$PL0$}
child{node [S] {$PL1$}
child{node [S] {$PL3$}
edge from parent node[ENL] {$x2 \leq 2$}}
child{node [S] {$PL4$}
child{node [S] {$PL5$}
child{node [S] {$PL7$}
edge from parent node[ENL] {$x2 \leq 3$}}
child{node [S, label = 2:More text here] {$PL8$}
edge from parent node[ENR] {$x2 \geq 4$}}
edge from parent node[ENL] {$x1 \leq 3$}}
child{node [S, label = 2:Another text here] {$PL6$}
edge from parent node[ENR] {$x1 \geq 4$}}
edge from parent node[ENR] {$x2 \geq 3$}}
edge from parent node[ENL] {$x1 \leq 4$}}
child{node [S, label = 2:Last text here] {$PL2$}
edge from parent node[ENR] {$x1 \geq 5$}};
\end{tikzpicture}
\caption{My Figure.}
\end{figure}
\end{document}
결과적으로 다음과 같은 수치를 얻어야 합니다.
음, 여기서는 두 가지 사항에 대한 도움이 필요합니다.
명령 을 사용해도
\centering
그림이 중앙에 위치하지 않습니다. 내가 여기서 무엇을 놓치고 있는 걸까요?그 서클 안에 더 많은 정보를 적어야 해요. 예를 들어 첫 번째 항목(PL0)에는 다음과 같은 추가 정보가 있어야 합니다.
나는 많은 것을 시도했지만 그 정보를 원에 맞추지 못했습니다.
답변1
- 그림~이다중심. 이를 확인하기 위해 텍스트 영역과
tikzpicture
. - 서클에 더 많은 내용을 추가하려면 노드 콘텐츠에 추가해야 합니다. 여러 줄 문자를 허용하려면
text width
와 같은 적절한 정렬(또는 ) 키를 추가해야 합니다align=center
.
\documentclass[
12pt,
oneside,
a4paper,
english,
french,
spanish,
brazil
]{abntex2}
\usepackage[showframe]{geometry}
\usepackage{float}
\usepackage{tikz}
\usetikzlibrary{calc, shapes}
\begin{document}
\begin{figure}[H]
\centering
\tikzset{thick,
tree node/.style = {align=center, inner sep=0pt, font = \scriptsize},
every label/.append style = {font=\scriptsize},
S/.style = {draw, circle, minimum size = 20mm, inner sep=0pt,
top color=white, bottom color=blue!20,
align=center}, %<-
ENL/.style = {% edge node left
font=\footnotesize, left=1pt},
ENR/.style = {% edge node right
font=\footnotesize, right=1pt},
grow = down,
sibling distance = 2.8cm,
level distance = 3cm
}
\begin{tikzpicture}
\node [S, label= 2:Some text here] {$PL0$}
child{node [S] {$PL0$\\ $x_1 = 4,333$ e\\ $x_2 = 2$ \\ $f = 42$}
child{node [S] {$PL3$}
edge from parent node[ENL] {$x2 \leq 2$}}
child{node [S] {$PL4$}
child{node [S] {$PL5$}
child{node [S] {$PL7$}
edge from parent node[ENL] {$x2 \leq 3$}}
child{node [S, label = 2:More text here] {$PL8$}
edge from parent node[ENR] {$x2 \geq 4$}}
edge from parent node[ENL] {$x1 \leq 3$}}
child{node [S, label = 2:Another text here] {$PL6$}
edge from parent node[ENR] {$x1 \geq 4$}}
edge from parent node[ENR] {$x2 \geq 3$}}
edge from parent node[ENL] {$x1 \leq 4$}}
child{node [S, label = 2:Last text here] {$PL2$}
edge from parent node[ENR] {$x1 \geq 5$}};
\draw (current bounding box.south west) rectangle (current bounding box.north east);
\end{tikzpicture}
\caption{My Figure.}
\end{figure}
\end{document}
패키지 를 보시는 것도 추천드려요 forest
.