突出显示森林中的部分节点

突出显示森林中的部分节点

在我的森林里(见代码)

\documentclass{standalone}
\usepackage[edges]{forest}
\begin{document}
\begin{forest}
  for tree={%
    folder,
    grow'=0,
    fit=band,
  }
[root
    [2020-01-01 10:05 part one part two] 
    [2020-01-01 10:10 part one part two] 
    [2020-01-01 10:10 part one part two] 
]
\end{forest}
\end{document}

我想强调每个节点的某些部分(非常表格化):

在此处输入图片描述

我认为使用 TikZ 单行矩阵是一个好主意,例如:

[<no idea>, tikz={\node[matrix, matrix of nodes, ampersand replacement=\&] (thematrix){
2020-01-01 10:05 \& Participant 1 \& created \\);]
% do the highlighting

但我被难住了:矩阵被放在树的顶部(我不知道如何将节点替换为矩阵)。也许我的方法完全错误。你有什么想法?

更新:不幸的是,Ignasi 提出的解决方案不适用于更复杂的树:

[root
    [a
        [2020-01-01 10:05 {\subnode[inner sep=1pt]{one}{part one}} part two] 
        [2020-01-01 10:10 part one part two] 
        [2020-01-01 10:10 part one part two, name=two] 
    ]
    [
        b 
        [...]
    ]
]

结果如下:

在此处输入图片描述

答案1

这是一种使用可能性tikzmark

在此处输入图片描述

\documentclass{article}
\usepackage{forest, tikz}
\useforestlibrary{edges}
\usetikzlibrary{tikzmark}

\begin{document}
\begin{forest}
  for tree={%
    folder,
    grow'=0,
    fit=band,
  }
[root
    [2020-01-01 10:05 \tikzmark{A}part one part two] 
    [2020-01-01 10:10 part one part two] 
    [2020-01-01 10:10 part one\tikzmark{B} part two, draw=green, thick] 
]
\end{forest}
\begin{tikzpicture}[remember picture, overlay]
\draw[draw, red, thick] ([shift={(-.1,.3)}]{pic cs:A}) rectangle ([shift={(.1,-.2)}]{pic cs:B});
\end{tikzpicture}
\end{document}

答案2

subnode这是一个来自tikzmark库和自己的节点的可能解决方案forest

\documentclass{standalone}
\usepackage[edges]{forest}
\usetikzlibrary{tikzmark}
\begin{document}
\begin{forest}
  for tree={%
    folder,
    grow'=0,
    fit=band,
  }
[root
    [2020-01-01 10:05 {\subnode[inner sep=1pt]{one}{part one}} part two] 
    [2020-01-01 10:10 part one part two] 
    [2020-01-01 10:10 part one part two, draw=green, name=two] 
]
\end{forest}
\begin{tikzpicture}[remember picture, overlay]
\draw[red] (one.north west) rectangle (one.east|-two.south);
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案3

@Sandy G 答案的一个小变化:使用 TiZ 库fit

\documentclass{article}
\usepackage[edges]{forest}
\usetikzlibrary{fit, 
                tikzmark}

\begin{document}
\begin{forest}
  for tree={%
    folder,
    grow'=0,
    fit=band,
  }
[root
    [2020-01-01 10:05 \tikzmark{A}part one part two]
    [2020-01-01 10:10 part one part two]
    [2020-01-01 10:10 part one\tikzmark{B} part two, draw=green, thick]
]
\end{forest}
\begin{tikzpicture}[remember picture, overlay,
FIT/.style = {draw=blue, thick, inner xsep=1pt,
              inner ysep=1.6ex, yshift=0.4ex, fit=#1}
                    ]
\node[FIT=(pic cs:A) (pic cs:B)] {};
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容