我有以下内容:
\begin{tikzpicture}
\matrix (m) [matrix of math nodes, row sep=1em, column sep=3em]{
\quad & a_1 & \quad \\
b & a_2 & \{ a_1, a_2 \dots a_n \} \\
\quad & a_n & \quad \\
\quad & \quad & \quad \\
};
\path[-latex]
(m-2-1) edge node[above] {$R$} (m-1-2)
(m-2-1) edge node[above] {$R$} (m-2-2)
(m-2-1) edge node[above] {$R$} (m-3-2)
(m-2-3) edge node[above] {$\in$} (m-1-2)
(m-2-3) edge node[above] {$\in$} (m-2-2)
(m-2-3) edge node[above] {$\in$} (m-3-2)
(m-2-2) edge[-, densely dotted] (m-3-2);
\draw[-latex] (m-2-1.south) |- (m-4-1.east) -| (m-2-3);
\end{tikzpicture}
并且想在用draw
命令创建的最后一条边上放置一个标签,但不知道如何操作。
正如您所见,这是一个特殊的边缘。
答案1
您可以node
向路径添加关键字。如果您在命令后添加关键字-|
,则pos=0.5
在节点选项中将引用水平线段和垂直线段之间的角、pos=0.25
引用水平线段的中点、pos=0.75
引用垂直线段的中点,等等。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}
\matrix (m) [matrix of math nodes, row sep=1em, column sep=3em]{
\quad & a_1 & \quad \\
b & a_2 & \{ a_1, a_2 \dots a_n \} \\
\quad & a_n & \quad \\
\quad & \quad & \quad \\
};
\path[-latex]
(m-2-1) edge node[above] {$R$} (m-1-2)
(m-2-1) edge node[above] {$R$} (m-2-2)
(m-2-1) edge node[above] {$R$} (m-3-2)
(m-2-3) edge node[above] {$\in$} (m-1-2)
(m-2-3) edge node[above] {$\in$} (m-2-2)
(m-2-3) edge node[above] {$\in$} (m-3-2)
(m-2-2) edge[-, densely dotted] (m-3-2);
\draw[-latex] (m-2-1.south) -- (m-4-1.center)-| node [below,pos=0.25] {Label}(m-2-3);
\end{tikzpicture}
\end{document}