0

I have this tree and would like to label the edges but have not been able to find out how. Could anyone explain me how to do thi, please. Any help is appreciated.

\documentclass[12pt, tikz]{article}
\usepackage{answers}
\usepackage{setspace}
\usepackage{graphicx}
\usepackage{slashbox}
\usepackage{enumitem}
\usepackage[colorlinks]{hyperref}
\usepackage{multicol}
\usepackage{booktabs}
\usepackage{amsmath}
\usepackage{mathrsfs}
\usepackage[table,x11names]{xcolor}
\usepackage[margin=1in]{geometry}
\usepackage{float}
\usepackage{amsmath,amsthm,amssymb}
\usepackage[utf8]{inputenc}
\usepackage {tikz}
\usepackage{multicol}
\usetikzlibrary{trees}
\usepackage{tikz-timing}[2014/10/29]
\usetikztiminglibrary[rising arrows]{clockarrows}
\usetikzlibrary {positioning}
\usepackage{xcolor}
\definecolor {processblue}{cmyk}{0.96,0,0,0}
\usepackage{caption}
\usepackage{array}
\newcolumntype{?}{!{\vrule width 2pt}}
\usepackage[spanish, es-tabla]{babel}
\makeatletter
\renewcommand{\@seccntformat}[1]{}
\makeatother
\setlength\parindent{24pt}
\usepackage{forest}
\usetikzlibrary{arrows.meta}

 
\begin{document}
 
\begin{center}
\begin{forest}
for tree = {
    circle, draw, 
    minimum size=5em,
    inner sep=4pt,
%
    s sep=15mm,
    l sep=20mm,
    edge={-Straight Barb} % arrows head defined in 'arrows.meta'
            }
[ItemA
    [ItemB]
    [ItemC]
]
\end{forest}
\end{center}

1 Answer 1

1

Use edge label= and complete with what you need (position, style, content). edge label in forest

\documentclass{article}
\usepackage{forest}
\usetikzlibrary{arrows.meta}
\begin{document}
 
    \begin{center}
        \begin{forest}
            for tree = {
                circle, draw, 
                minimum size=5em,
                inner sep=4pt,
            %
                s sep=15mm,
                l sep=20mm,
                edge={-Straight Barb}, % arrows head defined in 'arrows.meta'
                        }
            [ItemA
                [ItemB,edge label={node[midway,left]{left}}]
                [ItemC,edge label={node[midway,sloped,above]{right}}]
            ]
        \end{forest}
    \end{center}
\end{document}

If you need to label more than a few, you would find useful to define a general style inside your forest declaration, like this:

V2

        \begin{center}
        \begin{forest}
            for tree = {
                circle, draw, 
                minimum size=5em,
                inner sep=4pt,
            %
                s sep=15mm,
                l sep=20mm,
                edge={-Straight Barb}, % arrows head defined in 'arrows.meta'
                EL/.style = {edge label={node[midway, fill=white, inner sep=2pt,
                                        anchor=center]{#1}},},
                        }
            [ItemA
                [ItemB,EL=left]
                [ItemC,EL=right]
            ]
        \end{forest}
    \end{center}
1
  • And if you want to name your nodes in order to use them later in a tikzpicture, use the following syntax: [ItemB,name=N1,EL=left] where N1 is the node name which you can use later in any path.
    – SebGlav
    May 9, 2021 at 15:14

You must log in to answer this question.

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