我想在以下树的叶子右侧添加标签。我尝试将标签添加到连接箭头,但它们与节点上的标签重叠。
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}[>=stealth,sloped]
\matrix (tree) [
matrix of nodes,
minimum size=1cm,
column sep=2cm,
row sep=.5cm,
]
{
& & D \\
& B & \\
A & & E \\
& C & \\
& & F \\
};
\draw[->] (tree-3-1) -- (tree-2-2) ;
\draw[->] (tree-3-1) -- (tree-4-2) ;
\draw[->] (tree-2-2) -- (tree-1-3) ;
\draw[->] (tree-2-2) -- (tree-3-3) ;
\draw[->] (tree-4-2) -- (tree-3-3) ;
\draw[->] (tree-4-2) -- (tree-5-3) ;
\end{tikzpicture}
\end{document}
这是图片
答案1
您可以使用例如node[right=5mm] {text}
将节点向右移动。
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}[>=stealth,sloped]
\matrix (tree) [
matrix of nodes,
minimum size=1cm,
column sep=2cm,
row sep=.5cm,
]
{
& & D \\
& B & \\
A & & E \\
& C & \\
& & F \\
};
\draw[->] (tree-3-1) -- (tree-2-2) node[right=5mm] {foo};
\draw[->] (tree-3-1) node[right=5mm] {bar} -- (tree-4-2) ;
\draw[->] (tree-2-2) -- (tree-1-3) ;
\draw[->] (tree-2-2) -- (tree-3-3) ;
\draw[->] (tree-4-2) -- (tree-3-3) ;
\draw[->] (tree-4-2) -- (tree-5-3) ;
\end{tikzpicture}
\end{document}