在下面的示例中,您可以看到我遇到的问题的说明。我想从节点 s 到 6 绘制一个错误,但我想清除节点 1。\draw
从红色虚线可以看出,使用很容易做到。但是,我更希望找到正确的选项并将其包含在命令中\path
。非常感谢您的帮助。
\documentclass[border=10pt]{standalone}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
automata,
intersections,
positioning,
quotes,
matrix
}
\usetikzlibrary{shapes,arrows,fit}
\begin{document}
\begin{tikzpicture}[auto, node distance = 30mm and 40mm,
dot/.style = {circle, fill=red, inner sep=2pt, node contents={}},
every state/.style = {circle, draw=red, very thick},
every edge/.style = {draw=blue, line width=1pt, -Stealth,
shorten >=2pt, shorten <=2pt,
},
every edge quotes/.style = {auto, sloped, inner sep=2pt},
every label/.style = {rectangle, inner sep=2pt, font=\large},
mincut/.style = {draw=green!40!black, line width=3pt, dashed}
]
\node[state] at (0, 0) (1) [label=left:{ $ $}] {$1$};
\node[state] (4) [right= of 1, label=right:{ $ $}] {4};
\node[state] (2) [above= of 4, label=above:{ $ $}] {2};
\node[state] (6) [below right=2 and 1.7 of 4, label=below:{ $ $}] {6};
\node[state] (s) [above= of 1, label=above:{ $ $}] {s};
\path (s) edge["{$5,0$}"] (1)
edge["{$1,0$}"] (2)
edge["{$2,0$} ",out=180,in=200] (6)
(1) edge["{$2,2$}"] (2)
edge["{$3,1$}"] (4)
edge["{$2,2$}"] (6);
\draw[red,->,very thick,dashed] (s) .. controls (-3,-2) .. (6);
\end{tikzpicture}
\end{document}
答案1
我不会说使用附加项\draw
就不正确,但looseness
除了in
和out
角度之外,您还可以使用参数。例如,
edge["{$2,0$} ", out=230, in=180, looseness=1.4] (6)
或者,使用 指定自定义路径to path
,例如
edge["{$2,0$} ", to path={(\tikztostart) .. controls +(-4,-5) and +(-4,-1) .. (\tikztotarget) \tikztonodes}] (6)
请参阅第 14.13 节至路径操作在手册中。
下面我也使用该bbox
库来获得更好的边界框。
\documentclass[border=10pt]{standalone}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
automata,
intersections,
positioning,
quotes,
matrix,
bbox % <-- added
}
\usetikzlibrary{shapes,arrows,fit}
\begin{document}
\begin{tikzpicture}[auto, node distance = 30mm and 40mm,
dot/.style = {circle, fill=red, inner sep=2pt, node contents={}},
every state/.style = {circle, draw=red, very thick},
every edge/.style = {draw=blue, line width=1pt, -Stealth,
shorten >=2pt, shorten <=2pt,
},
every edge quotes/.style = {auto, sloped, inner sep=2pt},
every label/.style = {rectangle, inner sep=2pt, font=\large},
mincut/.style = {draw=green!40!black, line width=3pt, dashed}
]
\node[state] at (0, 0) (1) [label=left:{ $ $}] {$1$};
\node[state] (4) [right= of 1, label=right:{ $ $}] {4};
\node[state] (2) [above= of 4, label=above:{ $ $}] {2};
\node[state] (6) [below right=2 and 1.7 of 4, label=below:{ $ $}] {6};
\node[state] (s) [above= of 1, label=above:{ $ $}] {s};
\path [bezier bounding box] % for improved bounding box calculation, requires bbox library
(s) edge["{$5,0$}"] (1)
edge["{$1,0$}"] (2)
edge["{$2,0$} ", out=230, in=180, looseness=1.4] (6)
edge["{$2,0$} ", red, dashed, to path={(\tikztostart) .. controls +(-3,-7) and +(-5,0) .. (\tikztotarget) \tikztonodes}] (6)
(1) edge["{$2,2$}"] (2)
edge["{$3,1$}"] (4)
edge["{$2,2$}"] (6)
;
\end{tikzpicture}
\end{document}