如何调整路径\path (a) edge [edge, loop left] node {$1_a$} (a)
,使路径的起点和终点都靠近节点,但又不能太靠近以至于节点文本和节点内容重叠。我尝试使用shorten
边缘样式,但它似乎只适用于边缘的一端。
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary {calc}
\usetikzlibrary {automata}
\usetikzlibrary {positioning}
\usetikzlibrary {fit}
\begin{document}
\tikzset{edge/.style={
thin,
black,
->,
shorten >=8pt,
shorten <=8pt }
}
\tikzset{node-element/.style={
inner sep=1.5mm,
minimum size=1cm,
}
}
\begin{tikzpicture}[scale=1.5]
\coordinate (a) at (0,0);
\coordinate (b) at (2,0);
\coordinate (c) at (1,2);
\node [node-element] at (a) {a};
\node [node-element] at (b) {b};
\node [node-element] at (c) {c};
\draw[edge, bend left] (a) to node[above, pos=0.5] {$f$} (b);
\draw[edge, bend left] (b) to node[below, pos=0.5] {$f^{-1}$} (a);
\draw[edge] (c) to node[left, pos=0.5] {$h$} (a);
\draw[edge] (c) to node[right, pos=0.5] {$h^{-1}$} (b);
\path (a) edge [edge, loop left] node {$1_a$} (a)
(b) edge [edge, loop right] node {$1_b$} (b);
\end{tikzpicture}
\end{document}
答案1
通过将a
、定义b
为c
节点名称而不是零大小坐标来解决。
\documentclass[tikz]{standalone}
\begin{document}
\tikzset{
edge/.style={
thin,
black,
% ->,
% shorten >=8pt,
% shorten <=8pt
},
node-element/.style={
% inner sep=1.5mm,
% minimum size=1cm,
}
}
\begin{tikzpicture}[scale=1.5]
\node [node-element] (a) at (0,0) {a};
\node [node-element] (b) at (2,0) {b};
\node [node-element] (c) at (1,2) {c};
\draw[edge, bend left] (a) to node[above, pos=0.5] {$f$} (b);
\draw[edge, bend left] (b) to node[below, pos=0.5] {$f^{-1}$} (a);
\draw[edge] (c) to node[left, pos=0.5] {$h$} (a);
\draw[edge] (c) to node[right, pos=0.5] {$h^{-1}$} (b);
\path (a) edge [edge, loop left] node {$1_a$} ()
(b) edge [edge, loop right] node {$1_b$} ();
\end{tikzpicture}
\end{document}