I want "Child" at the left to fit in better like the rest and I want more space at the right side between the last nodes and the calculations P(x) = 1/2
this is the code:
\usepackage[latin1]{inputenc}
\usepackage{tikz}
\usetikzlibrary{trees}
%document already started
% Set the overall layout of the tree
\tikzstyle{level 1}=[level distance=3cm, sibling distance=2cm]
\tikzstyle{level 2}=[level distance=3cm, sibling distance=1cm]
% Define styles for bags and leafs
\tikzstyle{bag} = [text width=1em, text centered]
\tikzstyle{end} = [circle, minimum width=3pt,fill, inner sep=0pt]
% The sloped option gives rotated edge labels. Personally
% I find sloped labels a bit difficult to read. Remove the sloped options
% to get horizontal labels.
\begin{tikzpicture}[grow=right]
\node[bag] {Child}
child {
node[bag] {G}
child {
node[end, label=right:
{G $P(G\cap G)=\frac{1}{2}$}] {}
edge from parent
node[below] {0.5}
}
child {
node[end, label=right:
{B $P(G\cap B)=\frac{1}{2}$}] {}
edge from parent
node[above] {$0.5$}
}
edge from parent
node[below] {$0.5$}
}
child {
node[bag] {B}
child {
node[end, label=right:
{G $P(B\cap G)=\frac{1}{2}$}] {}
edge from parent
node[below] {$0.5$}
}
child {
node[end, label=right:
{B $P(B\cap B)=\frac{1}{2}$}] {}
edge from parent
node[above] {$0.5$}
}
edge from parent
node[above] {$0.5$}
};
\end{tikzpicture}
%end of document
I don't know hat I can do. I have tried to change the width which is 1em right now. But if I increase it the diagram gets even more out of shape and if I decrease it it completely covers "Child"
I have tried to make more spaces behind the last event (before the P(blabla) thing). But that didn't chnage anything.
repetitive spaces in latex are treated like a single space. If you'd like to manually increase the space, you could eg use \qquad
to avoid your Child
node from colliding with the lines, you can increase its text width. This will move it a bit further away from the lines
don't use \tikzstyle
, this macro is obsolete.
\documentclass{article}
\usepackage[latin1]{inputenc}
\usepackage{tikz}
\usetikzlibrary{trees}
\begin{document}
% Set the overall layout of the tree
\tikzset{level 1/.style={level distance=3cm, sibling distance=2cm}}
\tikzset{level 2/.style={level distance=3cm, sibling distance=1cm}}
% Define styles for bags and leafs
\tikzset{bag/.style={text width=1em, text centered}}
\tikzset{end/.style={circle, minimum width=3pt,fill, inner sep=0pt}}
% The sloped option gives rotated edge labels. Personally
% I find sloped labels a bit difficult to read. Remove the sloped options
% to get horizontal labels.
\begin{tikzpicture}[grow=right]
\node[bag,minimum width=2cm] {Child}
child {
node[bag] {G}
child {
node[end, label=right:
{G\qquad$P(G\cap G)=\frac{1}{2}$}] {}
edge from parent
node[below] {0.5}
}
child {
node[end, label=right:
{B\qquad $P(G\cap B)=\frac{1}{2}$}] {}
edge from parent
node[above] {$0.5$}
}
edge from parent
node[below] {$0.5$}
}
child {
node[bag] {B}
child {
node[end, label=right:
{G\qquad $P(B\cap G)=\frac{1}{2}$}] {}
edge from parent
node[below] {$0.5$}
}
child {
node[end, label=right:
{B\qquad $P(B\cap B)=\frac{1}{2}$}] {}
edge from parent
node[above] {$0.5$}
}
edge from parent
node[above] {$0.5$}
};
\end{tikzpicture}
\end{document}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.