1

I have a paper formatted like this one, i.e. two columns of text per page.

I've been trying to make a tree structure to fit inside of one column, but so far I've been unable to make it work.

There are resources about how to make tree structures using tikz, this one for instance, or this. But so far I've been unsuccessful in adapting those solutions to fit my current situation.

I wrote out by hand how I need the tree to look. It's important that the first node be able to spread out across two lines, using, I guess, // or /newline.

Thus far I have this:

\begin{figure}[t]
\centering

\caption{An illustration of a simple delete operation. \label{fig:simple}}
{
    \begin{tikzpicture}[level/.style={sibling distance = 5cm/#1, level distance = 1.5cm}, scale=0.6,transform shape]
    \node {\footnotesize educated at( Bush, University of Texas at Austin)}
    child
    {
        %node [treenode] {$Y$ \\ 50} 
        child
        {
            %node [treenode] {$Z$ \\ 40} 
            child
            {
                node [treenode] {$S1$ \\ 30}
                child
                {
                    node {\\60} 
                }
                {
                    node {\\60} 
                }
            }
            child
            {
                {
                    node {\\60} 
                }
                {
                    node {\\60} 
                } 
            }
        }
        child[edge from parent path ={(\tikzparentnode.-50) -- (\tikzchildnode.north)}]
        {
            node [subtree,yshift=0.4cm] (a) {}   % delay the text till later
        }
    }
    child[edge from parent path ={(\tikzparentnode.-30) -- (\tikzchildnode.north)}]
    {
        node [subtree,yshift=0.4cm] (b) {}       % delay the text till later
    }
;
% ------------------------------------------------ put the text into subtree nodes
\node[align=center,yshift=0.1cm] at (a) {$Z$\\200};
\node[align=center,yshift=0.1cm] at (b) {$Z$\\200};
\end{tikzpicture}
}
\end{figure}

and these packages:

\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usetikzlibrary{shapes.geometric,arrows,fit,matrix,positioning}

This is ideally how it would look:

enter image description here

6
  • Please: give us a complete, small document we can copy-paste-compile to see the problem. Fragments of code can be useful to explain things, but a complete, minimal example is really essential.
    – cfr
    Apr 29, 2015 at 15:05
  • What's treenode?
    – cfr
    Apr 29, 2015 at 15:09
  • This question is a near-duplicate of the more recent one asked by the same user. That one has been answered. Apr 29, 2015 at 15:13
  • @JasonZentz Shouldn't have wasted my time...
    – cfr
    Apr 29, 2015 at 15:33
  • @cfr, yeah, sorry -- I didn't see this earlier question until after I had answered the other one. I guess technically this question had a tikz MWE and the other one had a qtree MWE, but the same problems arise either way and are best dealt with using forest. Apr 29, 2015 at 15:43

1 Answer 1

1

Here's one way using forest which produces especially compact trees.

\documentclass[twocolumn]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{forest,kantlipsum}
\forestset{% adapted from page 52
  nice empty nodes/.style={
    delay={
      where content={}{
        shape=coordinate,
        for parent={
          for children={
            anchor=north
          }
        }
      }{}
    }
  }
}
\begin{document}
  \kant[1-2]
\begin{figure}[t]
\centering
\caption{An illustration of a simple delete operation. \label{fig:simple}}

    \begin{forest}
      nice empty nodes,
      for tree={
        align=center,
        parent anchor=south,
        edge path={
          \noexpand\path [draw, fill, \forestoption{edge}] (!u.parent anchor) circle (1.5pt) -- (.child anchor)\forestoption{edge label};
        }
      }
      [\textsc{data representation}\\{\footnotesize educated at (Bush, University of Texas at Austin)}
        [
          [Something\\here
          ]
          [Something\\else
          ]
        ]
        [
          [, tier=tier 1
            [
              [Q value]
              [English]
            ]
            [
              [Q value]
              [English]
            ]
          ]
          [
            [P value, tier=tier 1]
            [English]
          ]
        ]
      ]
    \end{forest}

\end{figure}
\kant[3-4]

\end{document}

tree

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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