In either tikz-qtree or qtree, is it possible to label or number different levels of a (vertical) tree? Such labels could be at the right or the left side of the whole tree.
Asked
Active
Viewed 3,775 times
3
brannerchinese
- 5,927
2 Answers
3
You can use \nodes to name some special nodes and allow getting access to their position in the tree and then use the named nodes to place the text. A little example placing text at both sides:
\documentclass[border=3pt]{standalone}
\usepackage{tikz-qtree}
\begin{document}
\begin{tikzpicture}
\Tree
[.\node (level0-right) {S};
[.NP
[.Det \node (level3-left) {the};
]
[.N cat
]
]
[.\node (level1-right) {VP};
[.V sat
]
[.\node (level2-right) {PP};
[.P on
]
[.\node (level3-right) {NP};
[.Det the
]
[.\node (level4-right) {N}; \node (level5-right) {mat};
]
]
]
]
]
\foreach \Value/\Text in {0/{Texto 1},1/{Texto 2},2/{Texto 3},3/{Texto 4},4/{Texto 5},5/{Texto 6}}
{
\node[anchor=west]
at ([xshift=1cm]{level5-right}|-{level\Value-right})
{\Text};
\node[anchor=east]
at ([xshift=-1cm]{level3-left}|-{level\Value-right})
{\Text};
}
\end{tikzpicture}
\end{document}
Gonzalo Medina
- 505,128
2
Just for the heck of it, here's Gonzalo Medina's example tree with prooftrees:
\documentclass[tikz,border=10pt]{standalone}
\usepackage{prooftrees}% version 0.8
\begin{document}
\begin{prooftree}
{
single branches
}
[S, just=explan 1
[NP, just=explan 2
[Det [the]]
[N [cat]]
]
[VP
[V [sat]]
[PP, just=explan 3
[P [on]]
[NP, just=explan 4
[Det, just=explan 5 [the, just=explan 6]]
[N [mat]]
]
]
]
]
\end{prooftree}
\end{document}
Note that the numbering on the left is automatic. (It can be switched off, but it is default.) Bear in mind, though, that the package is really designed specifically for logical proofs and not for other kinds of trees.
EDIT
Here's the same tree with some overlay specifications in Beamer:
This is using the standard definitions I use for tikzpictures generally and forest trees, in particular:
\documentclass{beamer}
\usepackage{prooftrees}% version 0.8
\tikzset{% set up for transitions using tikz with beamer overlays
invisible/.style={opacity=0,text opacity=0},
visible on/.style={alt=#1{}{invisible}},
alt/.code args={<#1>#2#3}{%
\alt<#1>{\pgfkeysalso{#2}}{\pgfkeysalso{#3}} % \pgfkeysalso doesn't change the path
},
transparent/.style={opacity=0.1,text opacity=0.1},
opaque on/.style={alt=#1{}{transparent}},
alerted/.style={color=red},
alert on/.style={alt=#1{alerted}{}},
}
\forestset{%
visible on/.style={%
for tree={%
/tikz/visible on={#1},
edge={/tikz/visible on={#1}}}},
opaque on/.style={%
for tree={%
/tikz/opaque on={#1},
edge={/tikz/opaque on={#1}}}},
alerted on/.style={%
for tree={%
/tikz/alerted on={#1},
edge={/tikz/alerted on={#1}}}},
}%
\begin{document}
\begin{frame}{A Tree}
\begin{prooftree}
{
single branches,
}
[S, just=explan 1
[NP, just=explan 2, alert on=<4->, for children={opaque on=<5->}
[Det [the]]
[N [cat]]
]
[VP
[V [sat]]
[PP, just=explan 3
[P [on]]
[NP, just=explan 4, alert on=<2>
[Det, just=explan 5, opaque on=<3-> [the, just=explan 6]]
[N [mat]]
]
]
]
]
\end{prooftree}
\end{frame}
\end{document}
-
A lot of the interesting functionality of
tikz-qtreedoesn't work withbeamer— "growing" trees upward, for instance. How doesprooftreereact to being in the same soup withbeamer? – brannerchinese Sep 20 '15 at 18:34 -
@brannerchinese Testing suggests it works similar to
forest, which is quite well. You just need a few TikZ andforeststyles and then you can use them within the tree. See edit for an example which uses transparency/opacity and alerted/regular transitions in the current example. – cfr Sep 20 '15 at 22:16 -
@brannerchinese What makes you say that
tikz-qtreedoesn't work well withbeamer? See the answer to http://tex.stackexchange.com/q/268578/3954 for an example of uncovering a tree upwards usingtikz-qtree. – Gonzalo Medina Sep 20 '15 at 22:22 -



tikz-qtreebut I've done this withqtree. However, it is not at all straightforward. I would not do it this way now I've got better options. I would either use or modify an experimental solution I have based onforest. (Use if the tree is proof-like in structure, or modify otherwise.) But maybe this isn't an option for you. An MWE would obviously help. – cfr Sep 19 '15 at 22:15prooftrees.styandjusttrees.sty. A recent-ish example is http://tex.stackexchange.com/questions/256184/tree-and-blocks/256245#256245. But ask if you plan to use any of this and I'll give you a current version of the package.prooftreesis at version 0.08 andjusttreesat version 0.04. If you search forprooftreesand look for answers by me, you can find some examples. – cfr Sep 19 '15 at 22:31tikz-qtreesolution see How can I align captions with each level of a tree drawn with tikz-qtree? – Alan Munn Sep 19 '15 at 23:51