4

I'm trying to draw a box around only part of the text in a tikz-qtree tree, but the closest I can do is this:

\documentclass{article}
\usepackage{tikz}
\usepackage{tikz-qtree}
\begin{document}

\begin{tikzpicture} \tikzset{every tree node/.style={align=center, anchor=north}}
\Tree
 [.parent
   [.child \node[draw]{boxed}; unboxed ]
 ]
\end{tikzpicture}
\end{document}

Unfortunately, this generates 'boxed' and 'unboxed' as child nodes of 'child', when I'd much prefer them to be part of the text in 'child'. I've been doing lineless labels on nodes like this -

[.{child \\ label} ]

and so I'd like to be able to do something like this -

[.{child \\ \node[draw]{boxed};unboxed} ]

giving '[boxed]unboxed' on a line under 'child'. The problem is that placing a node inside a [.{} ] element gives an undefined control sequence error. Is there any way around this issue, or am I just going to have to put the whole thing inside a boxed node?

2

Perhaps I am misunderstanding the question, Is something like this what you want?

\documentclass{article}
\usepackage{tikz}
\usepackage{tikz-qtree}
\begin{document}

\begin{tikzpicture} \tikzset{every tree node/.style={align=center, anchor=north}}
\Tree
 [.parent
   [.\node (a) {child \\ \fbox{boxed} unboxed}; ]
 ]
\end{tikzpicture}
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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