2

This question already has an answer here:

How can I introduce a line break into the labels of the end nodes in the following MWE? The Tikzpicture will include the line breaks if I remove the label=right: part and just leave label=' but that centers the labelabove' the node, rather than to the right.

How can I get the label to include the line breaks and also stay to the right of the end node?

\documentclass{article}

\usepackage[latin1]{inputenc}
\usepackage{tikz}
\usetikzlibrary{trees}
\begin{document}
\pagestyle{empty}


% Set the overall layout of the tree
\tikzstyle{level 1}=[level distance=3.5cm, sibling distance=3.5cm]
\tikzstyle{level 2}=[level distance=3.5cm, sibling distance=2cm]

% Define styles for bags and leafs
\tikzstyle{bag} = [text width=4em, 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, sloped]
\hspace{-60pt}
\node(A)[bag] {$S(3)$ $(Bet~3)$}
        child {
                node[bag] {$S(4)$ $Bet~4$}        
                        child {node[end, label=right: {Some text \\ Some text \\ Some text }] {}
                                edge from parent node[below] {$Quit$} node[above]  {}
                        }
                        child {
                                node[end, label=right: {Some text \\ Some text \\ Some text }] {}
                                edge from parent node[above] {$Bid$} node[below]  {}
                        }
                        edge from parent node[below] {$LLL$} node[above]  {}
        }
        child {
                node[bag] {$S(4)$ $Bet~4$}       
                child {
                                node[end, label=right: {Some text \\ Some text \\ Some text }] {}
                                edge from parent node[below] {$Quit$} node[above]  {}
                        }
                        child {
                                node[end, label=right:{Some text \\ Some text \\ Some text }] {}
                                edge from parent node[above] {$Bid$} node[below]  {}
                        }
                edge from parent node[above] {$WWW$} node[below]  {}
        };
\begin{scope}[]



\end{scope}
\end{tikzpicture}

\vspace{60pt}



\end{document}

marked as duplicate by Peter Grill, ChrisS, Adam Liter, Werner, Jesse Mar 30 '14 at 2:40

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2

Apply the every label/.style={align=left} option:

enter image description here

Note:

  • One can also use every node/.style={}, but in this case it seems more appropriate to use every label/.style={} as per TorbjørnT's comment.

  • It appears that when using the align= option one can not leave a blank space after the label=right:

    So

    label=right:{Some text \\ Some text \\ Some text}
    

    is ok, but

    label=right: {Some text \\ Some text \\ Some text}
    

    is not.

Alternatively, one could also use a \parbox{} to wrap the content in.


Code: every label/.style={align=left}:

\documentclass{article}

\usepackage[latin1]{inputenc}
\usepackage{tikz}
\usetikzlibrary{trees}
\begin{document}
\pagestyle{empty}

% Set the overall layout of the tree
\tikzstyle{level 1}=[level distance=3.5cm, sibling distance=3.5cm]
\tikzstyle{level 2}=[level distance=3.5cm, sibling distance=2cm]

% Define styles for bags and leafs
\tikzstyle{bag} = [text width=4em, 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, sloped, every label/.style={align=left}]
\hspace{-60pt}
\node(A)[bag] {$S(3)$ $(Bet~3)$}
        child {
                node[bag] {$S(4)$ $Bet~4$}        
                        child {node[end, align=center, label=right:{Some text \\ Some text \\ Some text}] {}
                                edge from parent node[below] {$Quit$} node[above]  {}
                        }
                        child {
                                node[end, label=right:{Some text \\ Some text \\ Some text}] {}
                                edge from parent node[above] {$Bid$} node[below]  {}
                        }
                        edge from parent node[below] {$LLL$} node[above]  {}
        }
        child {
                node[bag] {$S(4)$ $Bet~4$}       
                child {
                                node[end, label=right:{Some text \\ Some text \\ Some text}] {}
                                edge from parent node[below] {$Quit$} node[above]  {}
                        }
                        child {
                                node[end, label=right:{Some text \\ Some text \\ Some text}] {}
                                edge from parent node[above] {$Bid$} node[below]  {}
                        }
                edge from parent node[above] {$WWW$} node[below]  {}
        };
\end{tikzpicture}
\end{document}

Code: \parbox

\documentclass{article}

\usepackage[latin1]{inputenc}
\usepackage{tikz}
\usetikzlibrary{trees}
\begin{document}
\pagestyle{empty}

% Set the overall layout of the tree
\tikzstyle{level 1}=[level distance=3.5cm, sibling distance=3.5cm]
\tikzstyle{level 2}=[level distance=3.5cm, sibling distance=2cm]

% Define styles for bags and leafs
\tikzstyle{bag} = [text width=4em, 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, sloped]
\hspace{-60pt}
\node(A)[bag] {$S(3)$ $(Bet~3)$}
        child {
                node[bag] {$S(4)$ $Bet~4$}        
                        child {node[end, label=right: {\parbox[c]{3.0cm}{Some text \\ Some text \\ Some text}}] {}
                                edge from parent node[below] {$Quit$} node[above]  {}
                        }
                        child {
                                node[end, label=right: {\parbox[c]{3.0cm}{Some text \\ Some text \\ Some text}}] {}
                                edge from parent node[above] {$Bid$} node[below]  {}
                        }
                        edge from parent node[below] {$LLL$} node[above]  {}
        }
        child {
                node[bag] {$S(4)$ $Bet~4$}       
                child {
                                node[end, label=right: {\parbox[c]{3.0cm}{Some text \\ Some text \\ Some text}}] {}
                                edge from parent node[below] {$Quit$} node[above]  {}
                        }
                        child {
                                node[end, label=right:{\parbox[c]{3.0cm}{Some text \\ Some text \\ Some text}}] {}
                                edge from parent node[above] {$Bid$} node[below]  {}
                        }
                edge from parent node[above] {$WWW$} node[below]  {}
        };
\end{tikzpicture}
\end{document}
  • There's an every label style as well. – Torbjørn T. Mar 29 '14 at 23:59

Not the answer you're looking for? Browse other questions tagged or ask your own question.