7

I want to draw like -> 123 in this forest by $\overset{\downarrow }{\mathop{123}}\,$none as defaut This is my code

\documentclass[12pt]{standalone}
\usepackage{amsmath}
\usepackage{forest}
\begin{document}
\begin{forest}
[1[2[3[123]][4[124]][5[125]]]
[3[2[132]][4[134]][5[135]]]
[4[2[142]][3[143]][5[145]]]
[5[2[152]][3[153]][4[154]]]]
\end{forest}
\end{document}

enter image description here

How can I get like this, for example?

enter image description here

9

You can do it all at once or do it node wise:

\documentclass[preview]{standalone}
\usepackage{amsmath}
\usepackage{forest}

\begin{document}
\begin{forest}
for tree={
if n children=0{edge={->}}{},
},
[1[2[3[123]][4[124]][5[125]]]
[3[2[132]][4[134]][5[135]]]
[4[2[142]][3[143]][5[145]]]
[5[2[152]][3[153]][4[154]]]]
\end{forest}

\begin{forest}
[1[2[3[123,edge={->}]][4[124,edge={->}]][5[125,edge={->}]]]
[3[2[132,edge={->}]][4[134,edge={->}]][5[135,edge={->}]]]
[4[2[142,edge={->}]][3[143,edge={->}]][5[145,edge={->}]]]
[5[2[152,edge={->}]][3[153,edge={->}]][4[154,edge={->}]]]]
\end{forest}
\end{document}

enter image description here

  • If you want all lines to be like that, use for tree={edge={->}} – user11232 Nov 12 '14 at 4:12
  • If I want edge is a curve, how can I do it? – minthao_2011 Nov 12 '14 at 4:20
  • @minthao_2011 You have to draw them yourself, I think. – user11232 Nov 12 '14 at 4:45
  • @minthao_2011 Ask a new question if you want curves. Only you need to be more specific. What kind of curve? Which edges? – cfr Nov 12 '14 at 23:12
  • @cfr Thank you very much. I shall post another question as you said. – minthao_2011 Nov 13 '14 at 15:31
3

If you'd prefer forest to ensure accuracy for the terminal nodes, for example:

\documentclass[border=10pt]{standalone}
\usepackage{forest}

\begin{document}

\begin{forest}
  for tree={
  if n children=0{
    edge={->}}{},
  },
  delay={
    for tree={
      where n children=0{
        content/.wrap 3 pgfmath args={#1#2#3}{content("!uuu")}{content("!uu")}{(content("!u"))}
      }{},
      where level=1{
        content/.pgfmath={int(n()+1)}
      }{},
    },
  },
  [1[[3[]][4[]][5[]]]
    [[2[]][4[]][5[]]]
    [[2[]][3[]][5[]]]
    [[2[]][3[]][4[]]]
  ]
\end{forest}

calculate terminal nodes

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.