0

Goal: I would like to have a more systematic way to draw a shape around multiple nodes in a tikz-qtree, where the nodes are connected by edges.

enter image description here

  • Currently, I manually adjust inner xsep and inner ysep and the rotation for each shape until it encircles just the nodes I want.
  • Otherwise, by default, fit will make a big regular shape (a square or circle) that tends to scoop up some nodes or labels I don't want.
  • How can I define a kind of shape once and for all and not have to manually adjust xsep and ysep and rotate each time?

\documentclass{standalone}

\usepackage{tikz,tikz-qtree}

\begin{document}

\begin{tikzpicture} \Tree[.\node(T){T}; Subject [.\node(Aux){Aux}; Aux [.\node(Asp){Asp}; Adverb [.\node(V){V}; Verb Object ] ] ] ] \nodedraw,fit=(T)(Aux),style={ellipse,draw,red,inner xsep=0pt,inner ysep=-10pt,rotate=-40}{}; \node[draw,fit=(Asp)(V),style={rounded corners,inner ysep=-8pt,rotate=-28}]{}; \end{tikzpicture}

\end{document}

Psven
  • 111
  • 1
    Perhaps https://tex.stackexchange.com/questions/70999/highlight-a-group-of-nodes-in-a-tikz-tree#71064 https://tex.stackexchange.com/questions/71638/hobby-path-realization-in-convex-hull-approach is of interest. – Torbjørn T. Apr 03 '22 at 11:38

1 Answers1

1

Torbjørn T. helped me find a solution! Thanks!

\documentclass{standalone}

\usepackage{tikz,tikz-qtree} \usetikzlibrary{matrix}

\pgfdeclarelayer{background} \pgfsetlayers{background,main}

\tikzset{ my box/.style = { , line cap = round , line join = round } }

\newcommand{\highlight}[3]{ \path [my box, line width = 1.15 * #1, draw = #2] #3;

\pgfmathsetmacro{\innerlinewidth}{1.1 * #1}
\path [my box, line width = \innerlinewidth, draw = #2!10] #3;

}

\begin{document}

\begin{tikzpicture} \Tree[.\node(T){T}; Subject [.\node(Aux){Aux}; Aux [.\node(Asp){Asp}; Adverb [.\node(V){V}; Verb Object ] ] ] ] \begin{pgfonlayer}{background} \highlight{12mm}{blue}{(Asp) -- (V)} \end{pgfonlayer} \end{tikzpicture}

\begin{tikzpicture} \Tree[.\node(T){T}; Subject [.\node(Aux){Aux}; Aux [.\node(Asp){Asp}; Adverb [.\node(V){V}; Verb Object ] ] ] ] \begin{pgfonlayer}{background} \highlight{12mm}{red}{(T) -- (V)} \end{pgfonlayer} \end{tikzpicture}

\end{document}

enter image description here

Vincent
  • 20,157
Psven
  • 111
  • Torbjørn T.'s link led me to https://tex.stackexchange.com/questions/70648/highlighting-some-nodes-of-a-tikz-binomial-tree/70653#70653 where I found something in a solution by tcpaiva which I used in the above. – Psven Apr 03 '22 at 17:46
  • Now I have a new question -- in my first method, the shapes encircling the nodes were themselves nodes, so I could link them to other nodes with edges. Tikz-qtree ensured that these edges neatly started at the boundary of the shape, and I could specify which side they started from with “south” etc. Now, the shapes encircling the nodes are paths. Does anyone know how I can draw lines from their boundaries to link them to other nodes? – Psven Apr 03 '22 at 20:00
  • Belatedly, put coordinates on the paths as you create them. – cfr Jul 11 '23 at 01:56