我怎样才能将节点置于矩形/圆形中,并将标签放在箭头中间(看起来像文本标签上的断开箭头)?有什么方法可以减少代码长度吗?
\documentclass{standalone}
\usepackage{tikz-cd}
\begin{document}
\begin{tikzpicture}
\node[] (00) at (-0.5,1.5) {$(0,0)$};
\node[] (0) at (-0.5,0) {$0$};
\node[] (1) at (1,0) {$(1)$};
\node[] (2) at (2.5,0) {$(2)$};
\node[] (3) at (4.0,0) {$(3)$};
\node[] (4) at (4.8,0) {$\textbf{\dots}$};
\node[] (5) at (6,0) {$(y-1)$};
\node[] (6) at (8.0,0) {$(y)$};
\node[] (7) at (9.9,0) {$(y+1)$};
\node[] (8) at (11.9,0) {$(y+2)$};
\node[] (9) at (12.8,0) {$\textbf{\dots}$};
\node[] (10) at (11.8,-3) {$(x-b-1)$};
\node[] (11) at (8.9,-3) {$(x-b)$};
\node[] (12) at (6.2,-3) {$(x-b+1)$};
\node[] (13) at (5.0,-3) {$\textbf{\dots}$};
\node[] (14) at (3.8,-3) {$(x-1)$};
\node[] (15) at (1.5,-3) {$(x)$};
\node[] (16) at (-0.5,-3) {$(x+1)$};
\draw[->,blue] (0) edge ["a",bend left] (00) (00)edge ["a"] (0) ;
\draw[->] (1) edge ["b",bend left] (0) (0) edge ["a"] (1);
\draw[->] (2) edge [bend left] (0) (1) edge ["a"] (2);
\draw[->] (3) edge [bend left] (0)(2) edge["a"] (3);
\draw[->] (5) edge [bend left] (0) edge ["a"] (6);
\draw[->] (6) edge [bend left] (0) edge ["a",black] (7);
\draw[->,blue] (7) edge [bend right,"b"] (1) edge ["a",black] (8)(6) edge [bend right,"b"] (1);
\draw[->,red] (8) edge [bend right] (2)(7) edge [bend right,"a"] (2);
\draw[->] (10) edge ["a"] (11);
\draw[->] (11) edge ["a"] (12);
\draw[-,dashed,bend left] (9) edge (10);
\draw[->] (14) edge ["a"] (15) edge [bend left,"b",blue] (10);
\draw[->] (15) edge ["a"] (16) edge [bend right,"b",blue] (11)(15) edge [bend left,"b",blue] (10);
\draw[->,blue] (16) edge ["a",bend right] (11);
\end{tikzpicture}
\end{document}
答案1
这会将字母放在箭头的中间并绘制矩形节点。
\documentclass{standalone}
\usepackage{tikz-cd}
\tikzset{SmallNode/.style={draw,inner sep=0pt},%<- add circle here for circle nodes
every edge quotes/.style={fill=white}}
\begin{document}
\begin{tikzpicture}
\node[SmallNode] (00) at (-0.5,1.5) {$(0,0)$};
\node[SmallNode] (0) at (-0.5,0) {$0$};
\node[SmallNode] (1) at (1,0) {$(1)$};
\node[SmallNode] (2) at (2.5,0) {$(2)$};
\node[SmallNode] (3) at (4.0,0) {$(3)$};
\node[] (4) at (4.8,0) {$\textbf{\dots}$};
\node[SmallNode] (5) at (6,0) {$(y-1)$};
\node[SmallNode] (6) at (8.0,0) {$(y)$};
\node[SmallNode] (7) at (9.9,0) {$(y+1)$};
\node[SmallNode] (8) at (11.9,0) {$(y+2)$};
\node[] (9) at (12.8,0) {$\textbf{\dots}$};
\node[SmallNode] (10) at (11.8,-3) {$(x-b-1)$};
\node[SmallNode] (11) at (8.9,-3) {$(x-b)$};
\node[SmallNode] (12) at (6.2,-3) {$(x-b+1)$};
\node[] (13) at (5.0,-3) {$\textbf{\dots}$};
\node[SmallNode] (14) at (3.8,-3) {$(x-1)$};
\node[SmallNode] (15) at (1.5,-3) {$(x)$};
\node[SmallNode] (16) at (-0.5,-3) {$(x+1)$};
\draw[->,blue] (0) edge ["a",bend left] (00) (00)edge ["a"] (0) ;
\draw[->] (1) edge ["b",bend left] (0) (0) edge ["a"] (1);
\draw[->] (2) edge [bend left] (0) (1) edge ["a"] (2);
\draw[->] (3) edge [bend left] (0)(2) edge["a"] (3);
\draw[->] (5) edge [bend left] (0) edge ["a"] (6);
\draw[->] (6) edge [bend left] (0) edge ["a",black] (7);
\draw[->,blue] (7) edge [bend right,"b"'] (1) edge ["a",black] (8)(6) edge [bend
right,"b"'] (1);
\draw[->,red] (8) edge [bend right] (2)(7) edge [bend right,"a"] (2);
\draw[->] (10) edge ["a"] (11);
\draw[->] (11) edge ["a"] (12);
\draw[-,dashed,bend left] (9) edge (10);
\draw[->] (14) edge ["a"] (15) edge [bend left,"b",blue] (10);
\draw[->] (15) edge ["a"] (16) edge [bend right,"b",blue] (11)(15) edge [bend left,"b",blue] (10);
\draw[->,blue] (16) edge ["a",bend right] (11);
\end{tikzpicture}
\end{document}
图表仍然非常繁忙。
编辑: 像这样?
\documentclass{standalone}
\usepackage{tikz-cd}
\tikzset{SmallNode/.style={draw,inner sep=0pt},%<- add circle here for circle nodes
every edge quotes/.style={fill=white}
}
\begin{document}
\begin{tikzpicture}
\node[SmallNode] (00) at (-0.5,1.5) {$(0,0)$};
\node[SmallNode] (0) at (-0.5,0) {$0$};
\node[SmallNode] (1) at (1,0) {$(1)$};
\node[SmallNode] (2) at (2.5,0) {$(2)$};
\node[SmallNode] (3) at (4.0,0) {$(3)$};
\node[] (4) at (4.8,0) {$\textbf{\dots}$};
\node[SmallNode] (5) at (6,0) {$(y-1)$};
\node[SmallNode] (6) at (8.0,0) {$(y)$};
\node[SmallNode] (7) at (9.9,0) {$(y+1)$};
\node[SmallNode] (8) at (11.9,0) {$(y+2)$};
\node[] (9) at (12.8,0) {$\textbf{\dots}$};
\node[SmallNode] (10) at (11.8,-3) {$(x-b-1)$};
\node[SmallNode] (11) at (8.9,-3) {$(x-b)$};
\node[SmallNode] (12) at (6.2,-3) {$(x-b+1)$};
\node[] (13) at (5.0,-3) {$\textbf{\dots}$};
\node[SmallNode] (14) at (3.8,-3) {$(x-1)$};
\node[SmallNode] (15) at (1.5,-3) {$(x)$};
\node[SmallNode] (16) at (-0.5,-3) {$(x+1)$};
\draw[->,blue] (0) edge ["a",bend left] (00) (00)edge ["a"] (0) ;
\draw[->] (1) edge ["b",bend left,auto=left] (0) (0) edge ["a"] (1);
\draw[->] (2) edge [bend left] (0) (1) edge ["a"] (2);
\draw[->] (3) edge [bend left] (0)(2) edge["a"] (3);
\draw[->] (5) edge [bend left] (0) edge ["a"] (6);
\draw[->] (6) edge [bend left] (0) edge ["a",black] (7);
\draw[->,blue] (7) edge [bend right,auto=right,"b"] (1) edge ["a",black] (8)(6) edge [bend right,"b",auto =right] (1);
\draw[->,red] (8) edge [bend right,auto=right] (2)(7) edge [bend right,auto=right,"a"] (2);
\draw[->] (10) edge ["a"] (11);
\draw[->] (11) edge ["a"] (12);
\draw[-,dashed,bend left,auto=left] (9) edge (10);
\draw[->] (14) edge ["a"] (15) edge [bend left,auto=left,"b",blue] (10);
\draw[->] (15) edge ["a"] (16) edge [bend right,auto=right,"b",blue] (11)(15) edge [bend left,auto=left,"b",blue] (10);
\draw[->,blue] (16) edge ["a",bend right,auto=right] (11);
\end{tikzpicture}
\end{document}