Tikzpicture:来自文件的数据

Tikzpicture:来自文件的数据

我想从一系列输入文件中创建多棵树。文件需要使用什么语法才能创建以下树?

这就是我需要做的事情,但是从一个文件并使用循环而不是像这样手动进行:

\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}

我理解的唯一示例是使用.dat文件中的以下代码创建四个简单节点。

\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}; }

相关内容