下面的代码
\begin{tikzpicture}[auto,node distance=2cm,>=latex]
% Posizionamento manuale dei vertici
\node[circle,draw] (A) at (1,2) {A};
\node[circle,draw] (B) at (3,2) {B};
\node[circle,draw] (C) at (5,2) {C};
\node[circle,draw] (D) at (4,0) {D};
\node[circle,draw] (E) at (0,-1) {E};
\node[circle,draw] (F) at (2,0) {F};
\node[circle,draw] (S) at (-0.5,1) {S};
% Disegno degli archi con pesi
\draw (A) -- node {$2$} (B);
\draw (A) -- node {$2$} (S);
\draw (S) to[out=90,in=120] node[above] {$3$} (B);
\draw (S) -- node {$1$} (F);
\draw (S) -- node {$4$} (E);
\draw (E) -- node {$5$} (F);
\draw (E) to[out=0,in=220] node[above] {$2$} (D);
\draw (F) -- node {$3$} (D);
\draw (C) -- node {$3$} (D);
\draw (C) -- node {$3$} (B);
\draw (B) -- node {$6$} (D);
\draw (B) to[out=90,in=120] node[above] {$1$} (E);
\end{tikzpicture}
生成以下图表:
仔细检查后,很明显从 B 到 E 的边与其他边和节点 A 重叠。我正在寻求有关如何将这个特定边重新路由到节点 S 和 A 左侧的指导,以防止与其他边和节点重叠。任何有关实现此目的的帮助都将不胜感激。
答案1
解决方案是使用 键looseness=2
执行命令。同时更改\draw
键out
和。添加选项是为了使边界框不会变得太大。in
overlay
\documentclass[border=6pt]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[auto,node distance=2cm,>=latex]
% Posizionamento manuale dei vertici
\node[circle,draw] (A) at (1,2) {A};
\node[circle,draw] (B) at (3,2) {B};
\node[circle,draw] (C) at (5,2) {C};
\node[circle,draw] (D) at (4,0) {D};
\node[circle,draw] (E) at (0,-1) {E};
\node[circle,draw] (F) at (2,0) {F};
\node[circle,draw] (S) at (-0.5,1) {S};
% Disegno degli archi con pesi
\draw (A) -- node {$2$} (B);
\draw (A) -- node {$2$} (S);
\draw (S) to[out=90,in=120] node[above] {$3$} (B);
\draw (S) -- node {$1$} (F);
\draw (S) -- node {$4$} (E);
\draw (E) -- node {$5$} (F);
\draw (E) to[out=0,in=220] node[above] {$2$} (D);
\draw (F) -- node {$3$} (D);
\draw (C) -- node {$3$} (D);
\draw (C) -- node {$3$} (B);
\draw (B) -- node {$6$} (D);
\draw[looseness=2,overlay] (B) to[out=110,in=130] node[above] {$1$} (E);
\end{tikzpicture}
\end{document}
答案2
通过使用bbox
和quotes
库,图像代码变得更短、更清晰,并且生成的图像更加漂亮(周围没有多余的空白):
\documentclass[margin=3mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{bbox,
quotes}
\begin{document}
\begin{tikzpicture}[bezier bounding box,
C/.style = {circle, draw, inner sep=2pt},
every edge quotes/.style = {auto, font=\footnotesize, inner sep=2pt},
]
% Posizionamento manuale dei vertici
\begin{scope}[nodes=C]
\node (A) at (1, 2) {A};
\node (B) at (3, 2) {B};
\node (C) at (5, 2) {C};
\node (D) at (4, 0) {D};
\node (E) at (0,-1) {E};
\node (F) at (2, 0) {F};
\node (S) at (-.5,1){S};
\end{scope}
% Disegno degli archi con pesi
\draw (A) edge["$2$"] (S)
(A) edge["$2$"] (B)
(S) edge[bend left=60,"$3$"] (B)
(S) edge["$1$"] (F)
(S) edge["$4$"] (E)
(E) edge["$5$"] (F)
(E) edge[bend right,"$2$"] (D)
(E) edge[bend left=90, looseness=2, "$1$"] (B)
(F) edge["$3$"] (D)
(C) edge["$3$"] (D)
(C) edge["$3$"] (B)
(B) edge["$6$"] (D);
\end{tikzpicture}
\end{document}
顺便说一句,在您的代码片段中,您定义了箭头,但图中未使用箭头。因此,有点不清楚,您的图是有向的(边缘有箭头)还是无向的。我的 MWE 考虑后一种情况: