2

I am trying to replicate the following diagram

enter image description here

Which is quite simple but so far I have with boxes and links as showed in the code

\documentclass[tikz,12pt]{standalone}
\usetikzlibrary{calc,positioning,backgrounds,arrows.meta}
\usepackage{forest}
\pagestyle{empty}

 \begin{document}

 \begin{forest}
  for tree={
 child anchor=west,
 parent anchor=east,
 grow=east,
 draw,
 anchor=west,
  edge path={
  \noexpand\path[\forestoption{edge}]
    (.child anchor) -| +(-5pt,0) -- +(-5pt,0) |-
    (!u.parent anchor)\forestoption{edge label};
  },
 }
  [Rentas vitalicias
[Capital reservado
      [Todo [Muerte antes del retiro] [Muerte antes y despu\'es del retiro]
  ]
  [Mitad [Muerte antes del retiro] [Muerte antes y despu\'es del retiro]
  ]
]
[Capital cedido
  ]
  ]
]
]
 \end{forest}

\end{document}

Which results:

enter image description here

Any suggestion to make it more similar to the firs picture with longer lines and whithout boxes?

Thanks in advance for your time.

  • 1
    To remove the boxes delete the draw command below grow=east. The problem is the tree branches. – Sigur Jun 11 '18 at 12:34
2
\documentclass[tikz,12pt]{standalone}
%\usetikzlibrary{calc,positioning,backgrounds,arrows.meta}
\usepackage{forest}

 \begin{document}
 \begin{forest}
  for tree={
 child anchor=west,
 grow=east,
 anchor=west,
  edge path={
\noexpand\path[\forestoption{edge}]
    (.child anchor)  +(-5pt,-6pt) -- +(-5pt,6pt) --([xshift=-5pt]!s.anchor)
    (!u.parent anchor)\forestoption{edge label};
  },
 }
  [Rentas vitalicias,s sep=1cm
[Capital reservado
      [Todo,text width=3em
         [Muerte antes del retiro] 
         [Muerte antes y despu\'es del retiro]
  ]
  [Mitad,text width=3em
        [Muerte antes del retiro] 
        [Muerte antes y despu\'es del retiro]
  ]
]
[Capital cedido
  ]
  ]
]
]
\end{forest}
\end{document}

enter image description here

UPDATE: Changed the minimum text widths of two nodes and the vertical separation, thanks to Alan Munn!

  • +1 you might want to add text width=3em to the Mitad and Todo nodes so that the lines they dominate line up. For larger trees you'd need to find the largest node per level and adjust afterwards with some node walk magic. – Alan Munn Jun 11 '18 at 18:04
  • @AlanMunn Thanks! Do you know by chance if there is something like a minimum text width key or does one have to "invent" it? – user121799 Jun 11 '18 at 19:13
  • There's a minimum width key, but not a minimum text width key. But there's another problem with your tree. Because forest tries to make trees as compact as possible, it packs the Capital cedido node too close to the Capital reservado node making the structure unclear. Add s sep=2cm to the root node to pull them apart. – Alan Munn Jun 11 '18 at 19:20

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.