我制作了一个显示节点之间连接和关系的图表。以下是示例:
\documentclass[border=3.14mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,bending, positioning}
\begin{document}
\begin{tikzpicture}[>={Stealth[length=3mm, width=2mm]}]
\foreach \b/\angle/\d [count=\a] in %
{Rec-A/23/black,%
Rec-B/8/black,%
Rec-C/14/black,%
Rec-D/24/black,%
Rec-E/32/black,%
Rec-F/3/black,%
Rec-G/11/black,%
Rec-H/6/black}{%
\draw (\a*360/8: 4cm) node [circle,thick, draw=\d, text width=10mm, align=center] (\a) {\b \\ \angle};}
%
%Straight lines
%
\draw[->] (1) to[out=10,in=35,loop] node[right, midway,inner sep=2pt] {16} ();
\draw[->] (3) to[out=135,in=160,loop] node[left,midway, inner sep=2pt] {8} ();
\draw[->] (4) to[out=155,in=185,loop] node[left,midway, inner sep=2pt] {33} ();
\draw[->] (5) to[out=220,in=250,loop] node[left,midway, inner sep=2pt] {18} ();
\draw[->] (6) to[out=255,in=280,loop] node[below, midway,inner sep=2pt] {7} ();
\draw[->] (7) to[out=300,in=325,loop] node[right, midway, inner sep=2pt] {4} ();
\draw[->] (8) to[out=345,in=10,loop] node[right, midway, inner sep=2pt] {3} ();
%
%Curved lines
%%
\draw [draw = black,
arrows={- Stealth [left, black,length=8pt,bend,line width=0pt]}]
%(1)AAD
%(2)CanP
%(3)CvHMS to
(3) edge [thick, draw=black, bend left=0] node [sloped, anchor=south, pos=0.2] {1} (2)
(3) edge [thick, draw=black, bend left=0] node [sloped, anchor=south, below, pos=0.2] {10} (4)
(3) edge [thick, draw=black, bend left] node [sloped, anchor=south, below, pos=0.15] {1} (5)
(3) edge [thick, draw=black, bend left=0] node [sloped, anchor=south, above, pos=0.1] {2} (8)
%(4)GIH
(4) edge [thick, draw=black, bend right] node [sloped, anchor=south, pos=0.1] {1} (2)
(4) edge [thick, draw=black, bend left=0] node [sloped, anchor=south, pos=0.2] {1} (3)
(4) edge [thick, draw=black, bend right=0] node [sloped, below, pos=0.2] {11} (5)
(4) edge [thick, draw=black, bend left] node [sloped, anchor=south, pos=0.1] {1} (6)
%(5)ImmH
(5) edge [thick, draw=black, bend left=0] node [sloped, anchor=south, pos=0.1] {2} (2)
(5) edge [thick, draw=black, bend right] node [sloped, below, pos=0.1] {2} (3)
(5) edge [thick, draw=black, bend left=0] node [sloped, anchor=south, pos=0.25] {14} (4)
(5) edge [thick, draw=black, bend left=0] node [sloped, anchor=south, pos=0.2] {7}(6)
%(6)RspH
(6) edge [thick, draw=black, bend right] node [sloped, anchor=south, pos=0.2] {5} (4)
(6) edge [bend left=0] node [sloped, anchor=south, pos=0.2] {4} (5)
%(7)UrgH
(7) edge [thick, bend left=0, draw=black] node [sloped, anchor=south, pos=0.1] {2} (4)
%(8)WgtMgt
(8) edge [thick, draw=black, bend left=0] node [sloped, below, pos=0.1] {} (3)
(8) edge [thick, draw=black, bend left=0] node [sloped, below, pos=0.1] {} (4)
;
\end{tikzpicture}
\end{document}
相应的输出如下:
有没有办法让它更有吸引力/更有活力?每个节点都是一个“记录模块”,显示总计数。箭头上的数字表示连接。我还希望能够使用循环对这些卷曲箭头进行编程并添加自定义数字。
抱歉,我的请求比较“模糊”。
答案1
这类问题很难回答,因为每个人对吸引力的理解都不同。以下是我的看法:
我会弯曲所有的边缘:外边缘向外,这样它们就像一个连接所有节点的圆圈一样对齐,内边缘朝向图的中心,这有助于避免边缘重叠。
我将进一步尝试标准化标签在箭头上的距离和位置。我尝试将它们始终定位在外pos=0.2
(较短)边缘,pos=0.1
内(较长)边缘。当然,这不会导致与相关节点的距离完全相同,但我认为这仍然是一种好方法。我还尝试始终将标签放置在相应箭头的这一侧,该箭头具有鱼叉式箭头。我只在两种情况下偏离了此规则,这种放置会导致标签与另一条边重叠。
我最终稍微清理了一下代码(但我保留了循环中的颜色定义\foreach
,black
尽管始终是默认的,因为您可能想以某种方式在您的项目中使用它)。
\documentclass[border=3.14mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta, bending}
\begin{document}
\begin{tikzpicture}[>={Stealth[length=3mm, width=2mm]}]
\foreach \b/\angle/\d [count=\a] in {
Rec-A/23/black,
Rec-B/8/black,
Rec-C/14/black,
Rec-D/24/black,
Rec-E/32/black,
Rec-F/3/black,
Rec-G/11/black,
Rec-H/6/black%
}{
\node[circle, thick, draw=\d, text width=10mm, align=center] (\a) at (\a*360/8: 4cm) {\b \\ \angle};
}
% Loops
\begin{scope}[thick, ->, every node/.append style={midway, inner sep=2pt}]
\draw (1) to[out=10, in=35, loop] node[right] {16} (1);
\draw (3) to[out=135, in=160, loop] node[left] {8} (3);
\draw (4) to[out=155, in=185, loop] node[left] {33} ();
\draw (5) to[out=220, in=250, loop] node[left] {18} ();
\draw (6) to[out=255, in=280, loop] node[below] {7} ();
\draw (7) to[out=300, in=325, loop] node[right] {4} ();
\draw (8) to[out=345, in=10, loop] node[right] {3} ();
\end{scope}
% Curved lines
\begin{scope}[thick, >={Stealth[left, length=8pt, bend, line width=0pt]}, ->, every node/.append style={sloped}]
% (1) AAD
% (2) CanP
% (3) CvHMS to
\draw (3) to[bend left=15] node[above, pos=0.2] {1} (2);
\draw (3) to[bend right=15] node[above, below, pos=0.2] {10} (4);
\draw (3) to[bend left] node[above, above, pos=0.1] {1} (5);
\draw (3) to[bend right=15] node[above, above, pos=0.1] {2} (8);
% (4) GIH
\draw (4) to[bend right] node[above, pos=0.1] {1} (2);
\draw (4) to[bend left=15] node[above, pos=0.2] {1} (3);
\draw (4) to[bend right=15] node[above, pos=0.2] {11} (5);
\draw (4) to[bend left] node[below, pos=0.1] {1} (6);
% (5) ImmH
\draw (5) to[bend right=20] node[below, pos=0.1] {2} (2);
\draw (5) to[bend right] node[above, pos=0.1] {2} (3);
\draw (5) to[bend left=15] node[below, pos=0.2] {14} (4);
\draw (5) to[bend right=15] node[above, pos=0.2] {7} (6);
% (6) RspH
\draw (6) to[bend right] node[below, pos=0.1] {5} (4);
\draw (6) to[bend left=15] node[below, pos=0.2] {4} (5);
% (7) UrgH
\draw (7) to[bend right=15] node[below, pos=0.1] {2} (4);
%(8)WgtMgt
\draw (8) to[bend left=15] (3);
\draw (8) to (4);
\end{scope}
\end{tikzpicture}
\end{document}