Is there a way to draw (with tikz/tikz-qtree) a tree directly in the text, like the inline math command? For a small tree with 2 or 3 nodes? Thanks!
Asked
Active
Viewed 839 times
4
-
Sure, why not? What did you try that didn't work? – Alan Munn Oct 22 '13 at 15:48
1 Answers
3
Here is an example:
\documentclass{article}
\usepackage{pgf,tikz}
\usetikzlibrary{calc}
\makeatletter
\begin{document}
Hello \tikz[baseline=(X.base)]{%
\node[circle,inner sep=0pt,outer sep=0pt] (X){$\ $}; %
\draw (X.text) node[above,inner sep=0.1pt] (a) {\scalebox{0.7}{\tiny A}};
\draw ($(X.text)+(0.4,0)$) node[above,inner sep=0.1pt,rectangle] (b) {\scalebox{0.7}{\tiny B}};
\draw ($(X.text)+(0.2,1.7ex)$) node[below,inner sep=0.1pt,rectangle] (c) {\scalebox{0.7}{\tiny C}};
\draw (a) -- (c) -- (b);
}%
orld
\end{document}
The trick is to align a Tikz graphic at the baseline. Some code is borrowed from here: How to align a series of TikZ pictures at the baseline
The result looks like this:

The unit "ex" used in the example should roughly correlate with the height of the small "x" of a character. I did not use the Tikz tree library as it is probably overkill for such small trees.