2

I decided to use tikz forest in my book which I prepare to make the figures more attractive... but I realized that it is not so funny without any previous experience with it. After hours of googling I got to this:

enter image description here

\documentclass{article}
\usepackage[czech,english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{amsmath, amssymb, latexsym, graphicx, makeidx, fancyhdr, sectsty, enumitem, ntheorem}
\usepackage[font=small,labelfont=bf,aboveskip=0.1cm,position=top,labelsep=quad]{caption}
\usepackage[IL2]{fontenc}
\usepackage{amssymb}
\usepackage{amsfonts}
\usepackage{pifont}
\usepackage{listings}
\usepackage{xcolor}
\usepackage{forest}
\usepackage{tikz}
\begin{document}
\tikzstyle{ball}=[circle,shading=ball, ball color=red,minimum size=0.5cm]
\begin{forest}
    for tree={s sep=20pt,l sep=3cm,style=ball,grow=east}
%
[ ,name=root, ball color=blue, label={$\pmb{x}_1$},edge label = {node [right] {matched place} }
    [{}, 
 ]
]
\end{forest}
\end{document}

I would like to help with two problems: 1) I need to add a label to the edge (ideally below it). (more important) 2) If possible, I would need to replace the edge by the arrow. (less important)

I'am aware that there are many notations how to write the code of a tree, but this one is the only one where I succeeded with using of the ball style.

Thank you in advance for your comments and helps.

Frantisek

2 Answers2

4

you placed edge label on the wrong place ... where you put it the edge not exist. where exactly you like to have edge label is not clear. as you write, it appear right of edge (i doubt that this is desired).

enter image description here

a really minimal working example (mwe) is:

\documentclass{article}
\usepackage{amsmath}
\usepackage{forest}

\begin{document}
\tikzset{
ball/.style = {circle,
               shading=ball,
               ball color=#1,
               minimum size=0.5cm}
        }
\begin{forest}
for tree = {
  grow=east,
  l sep+=33mm,
  s sep=1mm,
            }
[ ,name=root, ball=blue, label={$\pmb{x}_1$},
    [ ,ball=red, edge label = {node [midway,above] {matched place} } ]
]
\end{forest}
\end{document}
Zarko
  • 296,517
  • Thank you (and also to @cfr ) very much for your answers. Now, the structure is much more comprehensible for me. You really helped me a lot. With best regards, Frantisek. – Frantisek Zapletal Sep 02 '17 at 08:41
  • @FrantisekZapletal, here is habit that instead saying "thank you" vote for received answers and the one, which the best solve your problem accept (by clicking on up-pen and check marks, which are on the top left side of each answer). happy tex-ing! – Zarko Sep 02 '17 at 10:08
3

As Zarko says, the root node has no edge so the edge label is ignore. Edges are drawn to nodes from their parent. Hence, the edge label needs to go with the child node.

To put the node below the edge, use, for example, midway, below in the usual way within the node options for the edge label. To add an arrow to a node's edge, use, for example, edge+={->}. To add arrows to all edges, just add this within the for tree. The example below assumes you want a single arrow, just move the option if you want it for the rest of the tree (if there is more of it to come).

\documentclass[border=10pt]{standalone}
\usepackage{forest,amsmath}
\begin{document}
\tikzset{ball/.style={circle,shading=ball, ball color=red,minimum size=0.5cm}}% \tikzstyle is deprecated
\begin{forest}
  for tree={s sep=20pt,l sep=3cm,style=ball,grow=east}
  [ ,name=root, ball color=blue, label={$\pmb{x}_1$}
    [, edge label = {node [midway, below] {matched place}}, edge+={->}
    ]
  ]
\end{forest}
\end{document}

<code>edge label</code> below and <code>edge</code> with arrow

cfr
  • 198,882