我正在尝试以一种美观的方式圈出图中的一组节点,并且我可以填充表面。
我试过,plot[smooth cycle]
但结果不太好。我也试过使用\shade
和,\fill
但我觉得我的边界路径连接得不是很好……
你能给我一些想法吗?
这是我想要得到的图表和圆圈类型。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows,automata,calc}
\begin{document}
\begin{figure}
\footnotesize
\begin{tikzpicture}[->,>=stealth',auto,semithick]
\tikzstyle{every state}=[fill=none,draw=black,text=black]
\tikzset{ficti/.style={draw=none,text=black,fill=none}}
\tikzset{mycut/.style={thick,double,-}}
\node[state,fill=gray] (SRC) [] {$src$};
\node[state,node distance=1.60cm] (S10) [right of=SRC] {$1_0$};
\node[state,node distance=1.20cm] (S20) [below of=S10] {$2_0$};
\node[state,node distance=1.20cm] (S30) [below of=S20] {$3_0$};
\node[state,node distance=1.20cm] (S40) [below of=S30] {$4_0$};
\node[state,node distance=1.90cm] (S21) [right of=S20] {$2_1$};
\node[state,node distance=1.90cm] (S31) [right of=S30] {$3_1$};
\node[state,node distance=1.90cm] (S22) [right of=S21] {$2_2$};
\node[state,node distance=1.90cm] (S32) [right of=S31] {$3_2$};
\node[state,node distance=5.70cm] (S41) [right of=S40] {$4_1$};
\node[state,node distance=1.90cm] (S42) [right of=S41] {$4_2$};
\node[ficti,node distance=4.70cm] (F01) [right of=S10] {};
\node[state,node distance=0.50cm] (S50) [above of=F01] {$5_0$};
\node[state,node distance=1.90cm] (S51) [right of=S50] {$5_1$};
\node[state,node distance=1.90cm] (S52) [right of=S51] {$5_2$};
\node[state,node distance=5.20cm,fill=gray] (SNK) [right of=F01] {$snk$};
\draw[mycut] (SRC) ++(90:15pt) coordinate(a1) arc (90:260:15pt) coordinate(a2);
\draw[mycut] (S20) ++(30:15pt) coordinate(b1) arc (30:85:15pt) coordinate(b2);
\draw[mycut] (S31) ++(210:15pt) coordinate(c1) arc (210:270:15pt) coordinate(c2);
\draw[mycut] (S41) ++(60:15pt) coordinate(d1) arc (60:90:15pt) coordinate(d2);
\draw[mycut] (S42) ++(-115:15pt) coordinate(e1) arc (-115:60:15pt) coordinate(e2);
\draw[mycut] (a2) to (b2);
\draw[mycut] (b1) to (c1);
\draw[mycut] (c2) to (d2);
\draw[mycut] (d1) to (e1);
\draw[mycut] plot [smooth] coordinates {(e2) ($(S10)!0.5!(S22)+(0.7,0.70)$) (a1)};
\end{tikzpicture}
\end{figure}
\end{document}
答案1
如果要填充该区域,最好先使用单个绘制命令,然后再进行填充。多条路径只会使填充变得更加困难,因为您需要填充每条路径,而且无论如何都无法保证获得良好的结果。
一些说明:
- 您只需要一个
\tikzset
,然后就可以在其中对样式进行分组。此外,继续使用它来代替\tikzstyle
。 arrows
被视为已弃用(尽管仍支持那些想要继续使用它的人),所以我用 替换了它arrows.meta
。箭头的语法略有不同,但并非完全不同。请参阅Tikz 手册了解更多信息。
输出
代码
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,automata,calc, backgrounds}
\tikzset{
every state/.style={fill=none,draw=black,text=black},
ficti/.style={draw=none,text=black,fill=none},
mycut/.style={thick,double,-}
}
\begin{document}
\begin{figure}
\footnotesize
\begin{tikzpicture}[->,-{Stealth},auto,semithick]
\node[state,fill=gray] (SRC) [] {$src$};
\node[state,node distance=1.60cm] (S10) [right of=SRC] {$1_0$};
\node[state,node distance=1.20cm] (S20) [below of=S10] {$2_0$};
\node[state,node distance=1.20cm] (S30) [below of=S20] {$3_0$};
\node[state,node distance=1.20cm] (S40) [below of=S30] {$4_0$};
\node[state,node distance=1.90cm] (S21) [right of=S20] {$2_1$};
\node[state,node distance=1.90cm] (S31) [right of=S30] {$3_1$};
\node[state,node distance=1.90cm] (S22) [right of=S21] {$2_2$};
\node[state,node distance=1.90cm] (S32) [right of=S31] {$3_2$};
\node[state,node distance=5.70cm] (S41) [right of=S40] {$4_1$};
\node[state,node distance=1.90cm] (S42) [right of=S41] {$4_2$};
\node[ficti,node distance=4.70cm] (F01) [right of=S10] {};
\node[state,node distance=0.50cm] (S50) [above of=F01] {$5_0$};
\node[state,node distance=1.90cm] (S51) [right of=S50] {$5_1$};
\node[state,node distance=1.90cm] (S52) [right of=S51] {$5_2$};
\node[state,node distance=5.20cm,fill=gray] (SNK) [right of=F01] {$snk$};
\begin{scope}[on background layer]
\filldraw[mycut, top color=cyan!50, bottom color=blue!50!black] (SRC) ++(90:15pt) coordinate(a1)
arc (90:260:15pt)
-- ($(S20)+(90:15pt)$)
arc (85:30:15pt)
-- ($(S31)+(210:15pt)$)
arc (210:270:15pt)
-- ($(S41)+(90:15pt)$)
arc (90:60:15pt)
-- ($(S42)+(-115:15pt)$)
arc (-115:60:15pt) [rounded corners=1cm]
-- (S21.east|-a1) [sharp corners] -- cycle;
\end{scope}
\end{tikzpicture}
\end{figure}
\end{document}