3

I'm looking for something like this (finite automat). I want to draw a specific node as endnode, that means this node should have two circles as border. I'm using forest to draw my trees

Currently I'm having this code to generate a tree. There should be an "endnode" for "Jack", "Java", "Jim", "Ron" and "Ronny" (always at the last matching node)

\documentclass{beamer}
\usepackage{forest}
\begin{document}
\begin{forest}
    for tree={
        circle,
        black,
        draw,
        minimum size = 2em,
        font=\Large,
        edge={->},
        s sep = 30pt
    }
    [{}
        [J, edge label={node[midway, left]{J}}
            [a, edge label={node[midway, left]{a}}
                [c,  edge label={node[midway, left]{c}}
                    [k,  edge label={node[midway, left]{k}}]]
                [v,  edge label={node[midway, left]{v}}
                    [a,  edge label={node[midway, left]{a}}]]]
            [i,  edge label={node[midway, left]{i}}
                [m,  edge label={node[midway, left]{m}}]]]
        [R,  edge label={node[midway, right]{R}}
            [o,  edge label={node[midway, right]{o}}
                [n,  edge label={node[midway, right]{n}}
                    [n,  edge label={node[midway, right]{n}}
                        [y,  edge label={node[midway, right]{y}}]]]]]]
\end{forest}
\end{document}
  • welcome to tex.se! please show us what you try so far! – Zarko Dec 12 '17 at 9:22
  • @Zarko updated post – Ian Fako Dec 12 '17 at 9:26
  • Thanks for posting your code, but this is not a complete example. Please always post code we can copy-paste-compile. Is it just one node you want with double or several? If several, is there a pattern? – cfr Dec 12 '17 at 23:58
  • @cfr Sorry, updated my code. There are several nodes, but there's not a real pattern. The tree stores names and each endnode should be a double bordered node ('Ron', 'Ronny'...) Currently solving this by the answer provided by Zarko – Ian Fako Dec 14 '17 at 14:45
  • @IanFako In that case you can add where n children=0{double}{} to the tree's preamble and all the terminal nodes will be double-bordered. You can then just add double to any additional nodes which need it in the tree. This is a bit more flexible if, say, you change your mind about how to designate the terminal nodes or something, and a bit less error-prone. – cfr Dec 16 '17 at 4:55
4

meanwhile i found a simple example in my examples barn:

\documentclass[tikz,multi,border=5pt]{standalone}
\usepackage{forest}

\begin{document}
    \begin{forest}
  for tree={
    draw=teal,
    line width=0.4pt,
    edge={draw=teal,very thin},
    grow=east,
    circle,
    l sep=19mm,
%    anchor=children,
    anchor=parent,  
  }
  [A, double, outer sep=0.5pt,
    [B]
    [C]
  ]
    \end{forest}
\end{document}

enter image description here

is this what you looking for?

  • ah yes, thank you, double is the option I was searching for – Ian Fako Dec 12 '17 at 9:41
3

Here's a less labour-intensive way of getting the pattern of edge labels you want. This is entirely off-topic and doesn't even attempt to answer the actual question, which Zarko has already covered.

\documentclass[border=10pt]{standalone}
\usepackage{forest}
\begin{document}
\begin{forest}
  for tree={
    circle,
    black,
    draw,
    minimum size = 2em,
    font=\Large,
    edge={->},
    s sep = 30pt
  },
  delay={
    for nodewalk={fake=r,1,descendants}{
      if edge label={}{}{
        edge label/.wrap value={ node [midway, left] {#1} }
      }
    },
    for nodewalk={fake=r,l,descendants}{
      if edge label={}{}{
        edge label/.wrap value={ node [midway, right] {#1} }
      }
    }
  }
  [
    [J, edge label=J
      [a, edge label=a
        [c,  edge label=c
          [k,  edge label=k]]
        [v,  edge label=v
          [a,  edge label=a]]]
      [i,  edge label=i
        [m,  edge label=m]]]
    [R,  edge label=R
      [o,  edge label=o
        [n,  edge label=n
          [n,  edge label=n
            [y,  edge label=y]]]]]]
\end{forest}
\end{document}

easier edge labelling

This is a bit trickier, perhaps, than the usual case in which people want all the labels for left-hand branches to go one way and all for right-hand branches to go the other. The pattern therefore seemed technically more interesting, though not necessarily aesthetically pleasing.

  • a new example for mastering forest (+1). btw, in which time zone you live? here in gmt is time to slip :-) – Zarko Dec 13 '17 at 0:15
  • @Zarko I'm horribly night-owl-ish ;). – cfr Dec 13 '17 at 1:12
  • ah, very the same as me ..., but now will go to slip :-) – Zarko Dec 13 '17 at 1:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.