Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I want to create a TIKZPICTURE using some data output from SAS. The following code creates a simple tree with a few nodes. I can't continue to add the values by hand as the actual tree I'm using has much more nodes and I've a number of trees to do.

How can I do something similar to the following, but for a much more complicated tree?

\begin{filecontents*}{assocFile.dat}
1/Node one
2/Node two
3/Node three
4/Node four
\end{filecontents*}

\documentclass{article}
\usepackage{catchfile,tikz}

\begin{document}

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

\end{document}

This is the kind of tree I need to create.

\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]
\node[bag] {1000}
        child {
                node[bag] {500}        
                        child {
                                node[end, label=right:
                                        {254}] {}
                                edge from parent
                                node[above] {L}
                                node[below]  {253}
                        }
                        child {
                                node[end, label=right:
                                        {252}] {}
                                edge from parent
                                node[above] {W}
                                node[below]  {251}
                        }
                        edge from parent 
                        node[above] {L}
                        node[below]  {501}
        }
        child {
                node[bag] {505}        
                child {
                                node[end, label=right:
                                        {254}] {}
                                edge from parent
                                node[above] {L}
                                node[below]  {253}
                        }
                        child {
                                node[end, label=right:
                                        {252}] {}
                                edge from parent
                                node[above] {W}
                                node[below]  {251}
                        }
                edge from parent         
                        node[above] {W}
                        node[below]  {502}
        };
\end{tikzpicture}
\end{document}
share

migration rejected from stackoverflow.com Mar 1 at 22:58

This question came from our site for professional and enthusiast programmers. Votes, comments, and answers are locked due to the question being closed here, but it may be eligible for editing and reopening on the site where it originated.

closed as unclear what you're asking by Joseph Wright Mar 1 at 22:58

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.

    
This is very doable, but I have a feeling parsing the input SAS file to the output TikZ code would be cumbersome if done inside the .tex file. Can you give an example of a .dat file and the associated TikZ code? (I suppose the .dat file for the example above would be enough) I could write a script in Python that accepts a SAS file and outputs the corresponding TikZ code. –  jlv Nov 8 '13 at 4:47
    
Welcome to TeX.SX! Your post was migrated here from Stack Overflow (and nobody noticed it). Please register on this site, too, and make sure that both accounts are associated with each other (by using the same OpenID), otherwise you won't be able to comment on or accept answers or edit your question. –  Qrrbrbirlbel Nov 8 '13 at 5:38
    
I second the comment from @JimboBimbo. We’re going to need an example of your input file to be able to say how possible this is with TikZ/TeX. You might find the forest package (or qtree or tikz-qtree) interesting which makes the input clearer. forest also supports automatic building of the tree. –  Qrrbrbirlbel Nov 8 '13 at 5:43

Browse other questions tagged or ask your own question.