0

I have a tree, the code and result look like below.

\documentclass[border=10pt]{standalone} 
\usepackage{tikz}
\usepackage{pgfplots}
\tikzset{
  treenode/.style = {shape=rectangle, rounded corners,
                     draw, align=center},
  root/.style     = {treenode},
  env/.style      = {treenode},
  leaf/.style     = {shape=circle,draw,align=center, scale=0.5},
  every node/.style       = {font=\tiny}
}
\begin{document}
\begin{tikzpicture}
  [
    grow                    = down,
    % sibling distance        = 10em,
    level 1/.style          = {sibling distance=3.7cm},
    level 2/.style          = {sibling distance=1.8cm},
    level 3/.style          = {sibling distance=1.2cm},
    level distance          = 1cm,
    edge from parent/.style = {draw, edge from parent path={(\tikzparentnode) -- (\tikzchildnode)}},
    %sloped
  ]
  \node [root] {R}
  child { node [env] {I}
        child{ node [env] {I}
                child{ node [leaf] {L}
                edge from parent node [ left] {LP}}
                child{ node [leaf] {L}
                edge from parent node [ right] {RP}}
        edge from parent node [ left] {LP}
        }
        child{ node [env] {I}
                    child { node [env] {I}
                    child{ node [leaf] {L}
                    edge from parent node [ left] {LP}}
                    child{ node [leaf] {L}
                    edge from parent node [ right] {RP}}
                    edge from parent node [ left] {LP}}
                    child{ node [leaf] {L}
                    edge from parent node [ right] {RP}}
            edge from parent node [ right] {RP}
        }
        edge from parent node [above right] {}
      }
    child { node [env] {I}
        child { node [env] {I}
            child{ node [] {$\ldots$}
            edge from parent node [left] {LP}}
            child{ node [] {$\ldots$}
            edge from parent node [right] {RP}}
            edge from parent node [left] {LP}
        }
        child{ node [leaf] {L}
            edge from parent node [right] {RP}
        }
        edge from parent node [above left] {}
      };
      \draw [red] (-3.7,-4.2) rectangle +(3.6, 3.5) node[xshift=-3cm, yshift=-0.2cm] {up};
      \draw [blue] (0.1,-3.2) rectangle +(2.9, 2.5) node[xshift=-2.3cm, yshift=-0.2cm] {down};

\end{tikzpicture} \end{document}

enter image description here

The edges that connect rounded corner nodes do not touch the nodes. But do the circle nodes. Can the edges extend to touch the nodes?

Also, I want to add a legend right below the blue box. Is there any nice way to add a legend to the place?

Q123
  • 119
  • 3

1 Answers1

1

You could use rounded rectangle from the shapes.misc library, and adjust the inner ysep:

enter image description here

\documentclass[border=10pt]{standalone} 
\usepackage{tikz}
\usetikzlibrary {shapes.misc}
\usepackage{pgfplots}
\tikzset{
  treenode/.style = {shape=rounded rectangle, inner ysep=2pt,
                     draw, align=center},
  root/.style     = {treenode},
  env/.style      = {treenode},
  leaf/.style     = {shape=circle,draw,align=center, scale=0.5},
  every node/.style       = {font=\tiny}
}
Sandy G
  • 42,558