如何調整路徑\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}