Respuesta1
Publico esta respuesta porque la respuesta anterior (Sina Ahmadi) no satisface una condición importante:las pendientes de las dos rectas de los hermanos son diferentes.
Código personalizable:
Definimos un nuevo comando \binary
. Su sintaxis es la siguiente:
\binary[slope left=<num>,slope right=<num>,height=<num>] (<node>) to (<node>) node {<text>} and (<node>) node {<text>};
nos dará
Tenga en cuenta que height
es de A.north
no de A.south
. Mejora necesaria.
Establecernos slope left=50,slope right=35,height=0.75
nos da
\documentclass[tikz,margin=3mm]{standalone}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\def\binary[slope left=#1,slope right=#2,height=#3] (#4) to (#5) node #6 and (#7) node #8; {
\node (#5) at ($(#4)+({180+#1}:{#3/cos(90-(#1))})$) {#6};
\node (#7) at ($(#4)+({-#2}:{#3/cos(90-(#2))})$) {#8};
\draw (#5.north)--(#4.south)--(#7.north);
}
\node (A) at (0,0) {A};
\binary[slope left=50,slope right=35,height=0.75] (A) to (1) node {1} and (B) node {B};
\binary[slope left=50,slope right=35,height=0.75] (B) to (2) node {2} and (C) node {C};
\binary[slope left=50,slope right=35,height=0.75] (C) to (3) node {3} and (D) node {D};
\binary[slope left=50,slope right=35,height=0.75] (D) to (4) node {4} and (E) node {E};
\binary[slope left=50,slope right=35,height=0.75] (E) to (5) node {5} and (F) node {F};
\end{tikzpicture}
\end{document}
Código menos personalizable:
Se \binary
ha cambiado un poco y la etiqueta de todos los nodos y los nombres de los nodos son los mismos ahora.
\documentclass[tikz,margin=3mm]{standalone}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\def\binary[slope left=#1,slope right=#2,height=#3] (#4) to (#5) and (#6); {
\node (#5) at ($(#4)+({180+#1}:{#3/cos(90-(#1))})$) {#5};
\node (#6) at ($(#4)+({-#2}:{#3/cos(90-(#2))})$) {#6};
\draw (#5.north)--(#4.south)--(#6.north);
}
\node (A) at (0,0) {A};
\binary[slope left=50,slope right=35,height=0.75] (A) to (1) and (B);
\binary[slope left=50,slope right=35,height=0.75] (B) to (2) and (C);
\binary[slope left=50,slope right=35,height=0.75] (C) to (3) and (D);
\binary[slope left=50,slope right=35,height=0.75] (D) to (4) and (E);
\binary[slope left=50,slope right=35,height=0.75] (E) to (5) and (F);
\end{tikzpicture}
\end{document}
Respuesta2
Respuesta3
Puedes usar forest
el paquete. Aquí hay un ejemplo de trabajo mínimo:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{forest}
\begin{document}
\begin{forest}
[A
[1][B
[2][C
[3][D
[4][E]
]
]
]
]
]
\end{forest}
\end{document}
lo que produce lo siguiente:
Puedes encontrar más ejemplos.aquí.