森林有与内容分开的节点标签

森林有与内容分开的节点标签

我正在尝试使用 forest 包构建一个层次树,其中每个节点都标有父节点标签+节点索引,例如: 在此处输入图片描述

我尝试了很多不同的方法,包括各种节点遍历。有两个问题:1) 标签直接出现在节点上方(例如,就在边缘线上)2) 我根本无法让这种递归标记工作 - 我能做的最好的就是让每个节点都标记为“parentIndex.nodeIndex”

答案1

由于您没有提供树的代码,我使用了一些我的树:

\documentclass[border=3mm]{standalone}
\usepackage[edges]{forest}

\begin{document}
\tikzset{every label/.style={xshift=-4ex, text width=6ex, align=right, 
                             inner sep=1pt, font=\footnotesize, text=red}}
  \begin{forest}
    for tree={              % style of tree nodes
      font=\footnotesize,
      draw, semithick, rounded corners,
            align = center,
        inner sep = 2mm,
                            % style of tree (edges, distances, direction)
             edge = {draw, semithick, -stealth},
    parent anchor = east,
     child anchor = west,
             grow = south,
    forked edge,            % for forked edge
            l sep = 12mm,   % level distance
         fork sep = 6mm,    % distance from parent to branching point
                }
    [Multimedia\\ RSS,label=1
      [Multimedia\\ Content,label=1.1]
      [Multimedia\\ Content,label=1.2.3.4]
    ]
  \end{forest}
\end{document}

在此处输入图片描述

答案2

我认为我不应该回答这种代我做的问题,尤其是那些显然有能力发布代码的人问的问题。不管怎样我都会回答,因为我喜欢树。

我严格按照原样为“代做”提供答案。我回答这些问题不仅仅是因为我想这样做,而完全是出于这个原因。希望我不会对解释或调整的要求表示同情。我花时间设置了这个问题。如果你想让我解释,你会帮助我帮助你。

\documentclass[border=10pt,multi,tikz]{standalone}
\usepackage[edges]{forest}
\begin{document}
\begin{forest}
  forked edges,
  for tree={
    align=center,
    draw,
    rounded corners,
    l sep'+=15pt,
  },
  my label/.style={
    label={[anchor=south east]above:#1},
  },
  before typesetting nodes={
    for descendants={
      temptoksa/.option=n,
      for nodewalk={
        while={>On>{level}{1}}{u,+temptoksa=.,+temptoksa/.option=n}
      }{},
      my label/.register=temptoksa,
    },
  }
  [Things it is time to speak of \dots
    [Shoes
      [An invention designed to\\protect the wealthy and\\trample the poor.]
    ]
    [Ships
      [Occasionally to be\\found in bottles.]
    ]
    [Sealing was
      [Not to be confused\\with ceiling wax.]
    ]
    [Cabbages
      [{A traditional medicine for\\poverty, everywhere believed\\efficacious by the rich\\and known ineffective\\by the poor.}]
    ]
    [Kings
      [Hereditary obsolescence.]
    ]
    [Why the sea is boiling hot
      [\emph{Non sequitur}.]
    ]
    [Whether pigs have wings
      [Falsehood.
        [\emph{A posteriori.}]
        [Contingent.]
      ]
    ]
  ]
\end{forest}
\end{document}

自动编号

相关内容