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.

Below is what picture i want enter image description here

Words of level 1: Rule

Words of level 2: Length Pattern Arcs

Words of level 3: T1 T2 A1

Words of level 4: term_index term pos_tag ne_tag term_index term pos_tag ne_tag start_index end_index semantic_type

String of bottom line: 2 [1][][][LOC] [2][][][LOC] -> 1-2:loc-cons

Below is my current code, and the picture generated by it.

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{trees}
\begin{document}

\pagestyle{empty}

\begin{tikzpicture}[edge from parent fork down]

\tikzstyle{level 2}=[level distance=1.3cm, sibling distance=10cm]
\tikzstyle{level 3}=[level distance=2.0cm, sibling distance=5cm]
\tikzstyle{level 3}=[level distance=2.0cm, sibling distance=3cm]
\tikzstyle{r}=[rotate=45]

\node {Rule}
    child {node {Length}
        child {node {2}}
    }
    child {node {Pattern}
        child {node {$T_1$}
            child {node[r] {term\_index}}
            child {node[r] {term}}
            child {node[r] {pos\_tag}}
            child {node[r] {ne\_tag}}
        }
        child {node {$T_2$}
            child {node[r] {term\_index}}
            child {node[r] {term}}
            child {node[r] {pos\_tag}}
            child {node[r] {ne\_tag}}
        }
    }
    child {node {Arcs}
        child {node {$A_1$}
            child {node[r] {start\_index}}
            child {node[r] {end\_index}}
            child {node[r] {semantic\_type}}
        }
    };


%    \node{2[][][][LOC] [2][][][LOC] \rightarrow 1-2:loc-cons};

\end{tikzpicture}

\end{document}

enter image description here

Can anyone help me with this, thanks a lot!

share|improve this question
6  
I would use tikz-qtree for this. Here are some related questions: How to draw up a hierarchical tree diagram for taxonomic classification and Joining two branches of a family tree. –  Alan Munn May 30 '12 at 16:42
    
@AlanMunn thanks, i will try it –  icycandy May 30 '12 at 16:52

1 Answer 1

up vote 3 down vote accepted

As you're stuck with the design of the bottom line, I thought it was easier to build the tree from this bottom line without using a tree-package but instead of using a pre-defined distance between levels and barycentric coordinates system.

I placed the labels of the bottom line below instead of above because then it seems clearer to me.

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc, positioning} 

\begin{document}
\begin{tikzpicture}

% place bottom line
\node (n00) {2};
\foreach \str/\l/\comment [count=\num]in {%
[1]/1cm/term\_index,
[\,]/1mm/term,
[\,]/1mm/pos\_tag,
[LOC]/1mm/ne\_tag,
[2]/1cm/term\_index,
[\,]/1mm/term,
[\,]/1mm/pos\_tag,
[LOC]/1mm/ne\_tag,
1-/2cm/start\_index,
2:/1mm/end\_index,
loc-cons/1mm/semantic\_type}
{
    \pgfmathtruncatemacro{\leftnum}{\num-1}
    \node[right=\l of n0\leftnum] (n0\num) {\str};
    \node[rotate=45,below left=0mm of n0\num.center] (c\num) {\textcolor{gray}{\sffamily\comment}};
}

% distance between two levels
\def\distance{3cm}

% level 1
\node (n10) at ($(n00)+(0,\distance)$) {};
\node (n11) at ($(barycentric cs:n01=1,n02=1,n03=1,n04=1)+(0,\distance)$) {$T_1$};
\node (n12) at ($(barycentric cs:n05=1,n06=1,n07=1,n08=1)+(0,\distance)$) {$T_2$};
\node (n13) at ($(barycentric cs:n09=1,n010=1,n011=1)+(0,\distance)$) {$A_1$};

% level 2
\node (n20) at ($(n10)+(0,\distance)$) {Length};
\node (n21) at ($(barycentric cs:n11=1,n12=1)+(0,\distance)$) {Pattern};
\node (n22) at ($(n13)+(0,\distance)$) {Arcs};

% level 3
\node (n30) at ($(barycentric cs:n20=1,n21=1,n22=1)+(0,\distance)$) {Rule};

% links
\draw (n00) -- (n20);
\foreach \num in {1,...,4}
    \draw ($(n0\num.north)+(0,1mm)$) |- ($(n11)+(0,-1)$);
\draw ($(n11)+(0,-1)$) -- (n11);
\foreach \num in {5,...,8}
    \draw ($(n0\num.north)+(0,1mm)$) |- ($(n12)+(0,-1)$);
\draw ($(n12)+(0,-1)$) -- (n12);
\foreach \num in {9,...,11}
    \draw ($(n0\num.north)+(0,1mm)$) |- ($(n13)+(0,-1)$);
\draw ($(n13)+(0,-1)$) -- (n13);
\draw (n11) |- ($(n21)+(0,-1)$) -- (n21);
\draw (n12) |- ($(n21)+(0,-1)$);
\draw (n13) -- (n22);
\foreach \num in {0,...,2}
    \draw ($(n2\num.north)+(0,1mm)$) |- ($(n30)+(0,-1)$);
\draw ($(n30)+(0,-1)$) -- (n30);
\end{tikzpicture}

\end{document}

Here is what the code above produces:

the tree

share|improve this answer
    
I'm doing my master thesis, as I'm not familiar with LaTeX, your answer help me a lot. Thank you! –  icycandy Jun 4 '12 at 16:49

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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