I am trying to get a hierarchical tree built using the forest package where each node is labelled with the parent nodes label + the node index, e.g,: enter image description here

I've tried a lot of different things, including various node walks. There are two issues: 1) labels appear directly above nodes (e.g., right on the edge line) 2) I can't get this recursive labelling working at all - the best I can do is make each nodes label "parentIndex.nodeIndex"

  • 1
    You expect us to retype your tree from the image just in order to create a style which labels the nodes? Only the last bit is interesting. The rest you've already done, so it's old hat.
    – cfr
    Commented Feb 3, 2017 at 2:31

2 Answers 2


Since you not provide code for your tree, I use some my tree:


\tikzset{every label/.style={xshift=-4ex, text width=6ex, align=right, 
                             inner sep=1pt, font=\footnotesize, text=red}}
    for tree={              % style of tree nodes
      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=]

enter image description here

  • Thanks, I actually wanted something where the numbers would be recursively appended, e.g., I wouldn't have to number them - I did figure something out but it's quite messy, I'll post it as an answer Commented Feb 3, 2017 at 3:23
  • @ZackNewsham And we actually wanted something like some code and not just a do-this-whole-thing-for-me picture.
    – cfr
    Commented Feb 3, 2017 at 4:09

I think I ought not answer do-it-for-mes like this one, especially ones asked by those clearly capable of posting code. I'm going to regardless because I like trees.

I provide answers to do-it-for-mes on a strictly as-is basis. I answer these questions not just because I want to but only, solely and purely for that reason. Expect me to be less than sympathetic to requests for explanations or adjustments. I spent the time setting the problem up. If you'd wanted me to explain, you'd have helped me to help you.

  forked edges,
  for tree={
    rounded corners,
    l sep'+=15pt,
  my label/.style={
    label={[anchor=south east]above:#1},
  before typesetting nodes={
    for descendants={
      for nodewalk={
      my label/.register=temptoksa,
  [Things it is time to speak of \dots
      [An invention designed to\\protect the wealthy and\\trample the poor.]
      [Occasionally to be\\found in bottles.]
    [Sealing was
      [Not to be confused\\with ceiling wax.]
      [{A traditional medicine for\\poverty, everywhere believed\\efficacious by the rich\\and known ineffective\\by the poor.}]
      [Hereditary obsolescence.]
    [Why the sea is boiling hot
      [\emph{Non sequitur}.]
    [Whether pigs have wings
        [\emph{A posteriori.}]


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .