I have trees in forest, where each node in the tree is annotated with a superscript (index) and a subscript (outdex), which I instantiate as separate nodes and position in the left and right corner of each tree node. However, I have to issues I've been struggling with for a while.
1) Right now, those get anchored with respect to the center of the node, but I'd like to take the width of each node label into account. If you see my example, the output is ok with nodes with short (1 letter) labels, but gets uglier with longer labels. E.g. with forget, I'd like them to be places wrt the edges of the word, not the node center. I'd like to modify my definition of index and outdex, but I cannot figure out how to refer to the width of a node label.
Of course I could just change the placement manually for this single tree, but I need to generate these as the output of a Python script, so I am trying to come up with a fixed solution.
One alternative I thought of would be to generate those annotations as ^\Index\Label_\Outdex
instead of separate nodes, but then I'd have problems placing boxes around the outdex.
2) The other things should be super simple, but somehow I also can't figure this out. I'd like to change the boxes around some of those nodes, so that they are a bit smaller and don't overlap with the main node label. I tried changing width and inner separator (e.g. \tikzset{boxed/.style = {draw, minimum size=0em, inner sep=.05em}}
), but nothing changes so I am guessing I am misunderstanding those commands. I tried rereading the manual but, alas, I am stuck.
I hope the question is clear! Any help would be greatly welcome!
\documentclass{article}
% load tikz and forest with more visible arrows
\usepackage{tikz}
\usepackage{forest}
\usetikzlibrary{arrows.meta}
% define annotations <- THESE ARE THE THINGS I AM TRYING TO FIX
\tikzset{annotation/.style = {font=\footnotesize}}
\tikzset{index/.style = {annotation, anchor= south east}}
\tikzset{outdex/.style = {annotation, anchor= north west}}
\tikzset{boxed/.style = {draw}}
\tikzset{empty/.style = {}}
\tikzset{non-final/.style = {opacity=70}}
\begin{document}
\begin{forest}
%
%%%%%%%%
% Tree %
%%%%%%%%
%
[$v$P, name=t1222121
[DP, name=subj
[the, name=t122212111]
[lawyer, name=t122212112]
]
[$v$', name=t12221212
[$v2$, name=t122212121]
[VP, name=t122212122
[forgets, name=t1222121221]
[DP, name=t1222121222
[his, name=t12221212221]
[briefcase, name=t12221212222]
]
]
]
]
%%%%%%%%%%%%%%%
% Annotations %
%%%%%%%%%%%%%%%
%
\node[index] at (t1222121) {18};
\node[outdex] at (t1222121) {19};
%
\node[index] at (subj) {19};
\node[outdex] at (subj) {20};
%
\node[index] at (t122212111) {20};
\node[outdex] at (t122212111) {21};
%
\node[index] at (t122212112) {20};
\node[outdex] at (t122212112) {22};
%
\node[index] at (t12221212) {19};
\node[outdex, boxed] at (t12221212) {24};
%
\node[index] at (t122212121) {24};
\node[outdex] at (t122212121) {25};
%
\node[index] at (t122212122) {24};
\node[outdex] at (t122212122) {26};
%
\node[index] at (t1222121221) {26};
\node[outdex] at (t1222121221) {27};
%
\node[index] at (t1222121222) {26};
\node[outdex] at (t1222121222) {28};
%
\node[index] at (t12221212221) {28};
\node[outdex] at (t12221212221) {29};
%
\node[index] at (t12221212222) {28};
\node[outdex] at (t12221212222) {30};
\end{forest}
\end{document}
\node[index] at (t1222121.north west) {18};
instead of\node[index] at (t1222121) {18};
, say? (BTW,\tikzset{boxed/.style = {draw,inner sep=0.5pt}}
does clearly make the boxes tighter.)\tikzset{annotation/.style = {font=\footnotesize,inner sep=0.5pt,outer sep=-2pt}} \tikzset{index/.style = {annotation, anchor= south}} \tikzset{outdex/.style = {annotation, anchor= north}}
this looks even better? BTW, why don't you add the labels already in the tree? You can say something likelabel=above right:{...}
.