我有这棵树,想给边缘贴上标签,但一直不知道怎么做。有人能帮我解释一下怎么做吗?任何帮助我都会很感激。
\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
使用edge label=
并完成您需要的内容(位置、样式、内容)。
\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}
如果需要标记多个,则在声明中定义通用样式会很有用forest
,如下所示:
\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}