1

I want to create a number of trees from a series of input files. What syntax would the file need to be in to create the following tree?

This is what I need done, but from a file and with loops rather than manually like this:

\documentclass{article}
\usepackage{catchfile,tikz}
\usepackage{filecontents}% http://ctan.org/pkg/filecontents
\usepackage{silence}% http://ctan.org/pkg/silence
\usepackage{tikz}
\usetikzlibrary{shapes,trees}
\begin{document}
\resizebox{1.0\textwidth}{!}{
\begin{tikzpicture}[grow=right, sloped,dot/.style={circle,fill,inner sep=0.5pt}]

\tikzstyle{level 1}=[level distance=5cm, sibling distance=4cm]
\tikzstyle{level 2}=[level distance=5cm, sibling distance=2cm]
\tikzstyle{level 3}=[level distance=5cm, sibling distance=0.9cm]
\tikzstyle{N} = [text opacity=0]
\tikzstyle{T} = [text opacity=100, align=center]
\node {Root (1000)}
    child {node[T] {Level 1a:  500\\ (Exp: 1000*0.5\textsuperscript{1})}
    child[T] {node {Level 2a: 250\\(Exp: 1000*0.5\textsuperscript{2})}      
    child[T] {node[T] {Level 3a: 125\\(Exp: 1000*0.5\textsuperscript{3})}  edge from parent node[below] {LLL}}
    child[T] {node[T] {Level 3b: 125\\(Exp: 1000*0.5\textsuperscript{3})}  edge from parent node[above] {LLW}}
    edge from parent node[below] {LL}
    }
    child[T] {node {Level 2b: 250\\(Exp: 1000*0.5\textsuperscript{2})}     
    child[T] {node[T] {Level 3c: 125\\(Exp: 1000*0.5\textsuperscript{3})}  edge from parent node[below] {LWL}}
    child[T] {node[T] {Level 3d: 125\\(Exp: 1000*0.5\textsuperscript{3})}  edge from parent node[above] {LWW}}
    edge from parent node[above] {LW}
    }
    edge from parent node[below] {L}
    }
    child {node[T] {Level 1b: 500 \\(Exp: 1000*0.5\textsuperscript{1})}     
    child[T] {node {Level 2d: 250\\(Exp: 1000*0.5\textsuperscript{2})}     
    child[N] {node[T] {Level 3e: 125\\(Exp: 1000*0.5\textsuperscript{3})}  edge from parent node[below,T] {WWL}}
    child[T] {node[T] {Level 3f: 125\\(Exp: 1000*0.5\textsuperscript{3})}  edge from parent node[above] {WWW}}
    edge from parent node[above] {WW}
    }
    child[T] {node {Level 2d: 250\\(Exp: 1000*0.5\textsuperscript{2})}     
    child[N] {node[T] {Level 3e: 125\\(Exp: 1000*0.5\textsuperscript{3})}  edge from parent node[below,T] {WWL}}
    child[T] {node[T] {Level 3f: 125\\(Exp: 1000*0.5\textsuperscript{3})}  edge from parent node[above] {WWW}}
    edge from parent node[above] {WW}
    }
    edge from parent node[above] {W}
    }
    ;
\end{tikzpicture}
}
\end{document}

The only example I understood was one that created four simple nodes with the following code from a .dat file.

\WarningFilter{latex}{Overwriting file}% Remove LaTeX warnings starting with "Overwriting file"
\begin{filecontents*}{assocFile.dat}
1/Node one
2/Node two
3/Node three
4/Node four
\end{filecontents*}

\CatchFileDef{\tempa}{assocFile.dat}{\endlinechar=`,}
\edef\tempb{\unexpanded{\foreach\a/\b in }{\unexpanded\expandafter{\tempa}}}
\tempb { \draw (\a,\a) node{\b}; }

closed as unclear what you're asking by Bobyandbob, Mensch, TeXnician, Troy, Stefan Pinnow Nov 5 '17 at 15:06

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • I had no time to read your source code, but you should read the resources page of the ubiquitous Graphviz project. There you'll find various tools such as dot2tex for converting file formats into visualizations. – juliohm Oct 4 '13 at 0:43
  • 1
    Does it have to be done all in LaTeX? Would it be possible to use e.g. Python to generate a .tex file? If so, then probably you could use XML for the input files. – Tom Bombadil Oct 21 '15 at 11:51

Browse other questions tagged or ask your own question.