Here is the code:
\begin{figure}[H]\centering
\begin{tikzpicture}
\node (tree)
{
\begin{forest}
for tree = {circle, draw, minimum width = 2.25em}
[\textcolor{red}{$S$}
[$A$, edge label = {node [midway, above left, font = \scriptsize] {\textcolor{red}{$1$}}}
[$B$, edge label = {node [midway, above left, font = \scriptsize] {$4$}}
[$D_1$, edge label = {node [midway, left, font = \scriptsize] {$7$}}
[$G_1$, edge label = {node [midway, left, font = \scriptsize] {$10$}}]
]
]
[$C$, edge label = {node [midway, above right, font = \scriptsize] {$2$}}
[$D_2$, edge label = {node [midway, above left, font = \scriptsize] {$3$}}
[$G_2$, edge label = {node [midway, left, font = \scriptsize] {$6$}}]
]
[$G_3$, edge label = {node [midway, above right, font = \scriptsize] {$4$}}]
]
]
[$G_4$, edge label = {node [midway, above right, font = \scriptsize] {$12$}}]
]
\end{forest}
};
\end{tikzpicture}
Here is the output:
Here are a couple of questions concerning this:
I would like to color the boundary of nodes (circles) red, as well as make some of the edges red. Is there a way to do so?
For the edge labels, as for horizontal and vertical positions as in
node[midway, right]
ornode[midway, above]
, this is ok for vertical and horizontal edges, respectively, but for slanted edges, as they can take on any angle, I would like to label the edges such that they are of the same distance as the horizontal and vertical labels, but in a perpendicular direction to the slanted edges. How does one code it up?How to make the edge lengths longer? For all the edges? For some edges?
Any help would be appreciated. Thank you in advance!
tikzpicture
.tikzpicture
?\savebox
and the\savebox
in a node.\begin{document} \savebox{forest1}{%tree content} \begin[tikzpicture} \node(tree){\usebox{forest}} \end{tikzpicture} \end{document}
Also, do you know how one can color the tree's nodes and edges as well as label the edges like what I want for slanted edges?\newsavebox\SomethingWithBackslash \savebox\SomethingWithBackslash{<tree>} \begin[tikzpicture} \node(tree){\usebox\SomethingWithBackslash}; \end{tikzpicture}.