5

I am using the forest package to draw a tree outlining a root interface that is implemented by an arrangement of classes inheriting from each other. I still need to work on the graphical layout, but I think I've got the basics:

\documentclass{minimal}
\usepackage{tikz}
\usepackage[edges]{forest}
\begin{document}
\begin{forest}
  my label/.style={
    label={[font=\ttfamily]right:{#1}},
  },
  for tree={
    folder,
    font=\ttfamily,
    s sep=0.1cm,
    grow'=0,
    edge={line width=1pt},
    fit=band,
  },
  [interface
    [base class
      [abstract intermediate class
        [implementation class 1]
        [implementation class 2]
        [implementation class 3]
      ]
      [different class
        [implementation class 4]
      ]
    ]
  ]
\end{forest}
\end{document}

I need to add another set of descriptions to the tree. Each class has a text associated with it, and I need to display that text with a different font next to the tree on the right-hand side. I want to display the text on the same height as the technical class name that makes up the tree node, but I want to align the descriptions horizontally to achieve a "cleaner" look. Here is a mockup with some lines added to show the intended alignment:

enter image description here

3
  • Please don't use minimal for examples. It is not suitable.
    – cfr
    Commented Oct 30, 2017 at 4:39
  • @cfr Why is that so?
    – vwegert
    Commented Oct 30, 2017 at 6:31
  • It is not designed for it and yields errors which you would not get with a proper class. There is a question about it if you search.
    – cfr
    Commented Oct 30, 2017 at 23:41

1 Answer 1

5

Something like this?

tag me

\documentclass[border=10pt]{standalone}
\usepackage[edges]{forest}
\begin{document}
\begin{forest}
  my label/.style={
    label={[font=\ttfamily]right:{#1}},
  },
  for tree={
    folder,
    font=\ttfamily,
    s sep=0.1cm,
    grow'=0,
    edge={line width=1pt},
    fit=band,
  },
  write me/.style={
    tikz+={
      \node [anchor=mid west, red] at (.mid -| write me coord) {#1};
    },
  },
  tikz+={
    \coordinate (write me coord) at (current bounding box.east);
  }
  [interface, write me=tag 1
    [base class, write me=tag 2
      [abstract intermediate class, write me=tag 3
        [implementation class 1, write me=tag Z]
        [implementation class 2, write me=tag D]
        [implementation class 3, write me=tag T]
      ]
      [different class, write me=tag S
        [implementation class 4, write me=tag W]
      ]
    ]
  ]
\end{forest}
\end{document}

You must log in to answer this question.

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