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 am trying to convert my tree-dvips trees into something that is compatible with xelatex. I had a look at the tikz-qtree package, but it seems to be impossible to set complex nodes.

In the old qtree package there was a low level syntax that I could use (leaf, branch, ...), but this seems to be gone. In tree-dvips I just put the complex stuff inside of \node{...}, but how do I do this with tikz-qtree?

\documentclass{scrbook}

\usepackage{tikz-qtree}

\begin{document}

This is some text and the figure should be the size of the text not larger and not smaller.
\begin{figure}[h]
\begin{tikzpicture}
\Tree[.{V[\begin{tabular}[t]{@{}l@{}}
             spr eliste,\\
             comps eliste ]
             \end{tabular}} [.NP dogs ] [.V sleep] ]
\end{tikzpicture}

\end{figure}

This is some text and the figure should be the size of the text not larger and not smaller.

\end{document}

Edit: Tried to do without the tabular environment, but adding the left/north option gives me a funny result. Look at the "man" in the following figure. It is too much north.

\documentclass{scrbook}

\usepackage{tikz-qtree}
\tikzset{every tree node/.style={align=left, anchor=north}}

\begin{document}

\begin{tikzpicture}
\tikzset{level 1+/.style={level distance=3\baselineskip}}
\tikzset{frontier/.style={distance from root=12\baselineskip}}
\Tree[.{V[{\sc comps} { }]}
          [.{{1} NP} man ]
          [.{V[{\sc comps} { {1} }]} 
               [.{{2} NP} ketābāro ]
               [.{V[{\sc comps} { {1}, {2} }]}
                    [.{{3} PP} \edge[roof]; {be Sepide} ]
                    [.{V[{\sc comps} { {1}, {2}, {3} }]} dādam ]
               ]
          ]
]
\end{tikzpicture}

\end{document} 
share|improve this question
add comment

2 Answers 2

up vote 1 down vote accepted

I am not sure if this is what you want to achieve:

\documentclass{scrbook}
\usepackage{tikz-qtree}

\begin{document}

This is some text and the figure should be the size of the text not larger and not smaller.

\begin{figure}[!ht]
\begin{tikzpicture}
\Tree [.V [.{\begin{tabular}[t]{@{}l@{}} spr eliste \\ comps eliste \end{tabular}} ] [.N tree ] ]
\end{tikzpicture}
\end{figure}

This is some text and the figure should be the size of the text not larger and not smaller.

\end{document}

enter image description here

share|improve this answer
    
Thank you very much! I am really impressed by the speed in which one gets things done with stackexchange! Thanks all of you! My mistake was the missing space before ]. I always thought my complex table was the problem. –  Stefan Müller Sep 11 '12 at 19:54
add comment

There's no need to wrap your complex node in a tabular environment. TikZ allows nodes to contain newlines provided you specify an explicit alignment for the text in the node.

So add the following line to your document:

\tikzset{every tree node/.style={align=left, anchor=north}}

or

\tikzset{every tree node/.style={align=center, anchor=north}}

And you don't need to use the tabulars at all.

\documentclass{scrbook}

\usepackage{tikz-qtree}
\tikzset{every tree node/.style={align=left, anchor=north}}
\begin{document}

\Tree [.V [.{[spr eliste \\ comps eliste]} ] [.NP dogs ] [.V sleep ] ] 

\end{document}

output of code

With respect to your edit, using anchor=north isn't appropriate for terminal nodes of the tree if you need the nodes to line up on a baseline. (I don't usually draw trees this way, so I wasn't thinking much about that.)

You can solve this problem by using:

\tikzset{every internal node/.style={align=left, anchor=north}}

or

\tikzset{every internal node/.style={align=center, anchor=north}}

The internal node key targets all the non-terminals in the tree.

share|improve this answer
    
Yes, but then "spr" and "comps" are not aligned. Maybe it is better to add space that corresponds to the width of "[" rather than using the tabular environment. –  Stefan Müller Sep 12 '12 at 11:57
    
Ok. It wasn't clear from your question whether you were using the tables for alignment or simply to allow line breaks in your node labels. If you need alignment, then the tabular is the way to go. For this kind of thing, I usually use a macro. See (the answers to) Understanding a \@for loop for an example of one that I use. –  Alan Munn Sep 12 '12 at 14:55
add comment

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.