编辑:答案重写

编辑:答案重写

我正在尝试构建一条从 s 到名为 x 的 a 的曲线边以及一条从 s 到名为 y 的 b 的曲线边。

除了正确地将它们弯曲的问题之外,我还想给它们一个背景,就像在这个问题中或者在这张图片中图片

\documentclass[a4paper,10pt]{article}
\usepackage{tikz}
\usetikzlibrary{automata,positioning,arrows,matrix,backgrounds}
\begin{document}
\begin{tikzpicture} [->,>=stealth',shorten >=1pt,auto,node distance=2.5cm,thick,main node/.style={circle,fill=gray!25,draw,font=\sffamily\Large\bfseries}]

    \node[main node] (1)                    {$s$};
    \node[main node] (2) [below of=1]       {a};
    \node[main node] (3) [ right of=2]      {b};
    \node[main node] (4) [below of=2]       {$t$};

    \path[every node/.style={font=\sffamily\small}]
    (2)     edge [bend left=50]     node    {$r^{-1}$}  (3)
    (3) edge [bend left=50,dashed]  node    {$r$}       (2);

    \draw (1)       .. controls +(1, -1)    and +(-1, 1) .. (2) node[midway,above left] {$x$};
    \draw (1) [dashed]  .. controls (1, 2)  and (2,0) ..        (3) node[midway,right]      {$y$};

    % \draw background here ???!

\end{tikzpicture}
\end{document}

我尝试了很多类似链接问题的方法,但没有得到好的解决方案。有什么建议吗?

最后它应该像图片中这样:

![][3]

答案1

编辑:答案重写

看到预期结果后:

  1. 对于“弯曲”的线条,我定义了一种wavy使用蛇形装饰的样式
  2. 对于背景灰色标记,使用pgfonlayer并以较大的线宽重新绘制那些线条。

 

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning,arrows,backgrounds,decorations.pathmorphing}

\tikzset{
  wavy/.style = {
     decorate,
     decoration = {snake, amplitude=1.5mm, segment length=8mm}
  },
  main node/.style={circle,fill=gray!25,draw,font=\sffamily\Large\bfseries}
}

\begin{document}
\begin{tikzpicture} [->,>=stealth',shorten >=1pt,auto,
    node distance=2.5cm,thick]

    \node[main node] (1)                    {$s$};
    \node[main node] (2) [below of=1]       {a};
    \node[main node] (3) [right of=2]       {b};
    \node[main node] (4) [below of=2]       {$t$};

    \path[every node/.style={font=\sffamily\small}]
    (2) edge [bend left=50]         node    {$r^{-1}$}  (3)
    (3) edge [bend left=50,dashed]  node    {$r$}       (2);

    \path (1)  edge[out=250, in=110, wavy]
               node[inner sep=2mm, above left] {$x$}
          (2);

    \path (1) edge[out=0, in=80, wavy, dashed]
              node[inner sep=2mm, above right]   {$y$}
          (3);

    % \draw background here ???!
    \begin{pgfonlayer}{background}
     \begin{scope}[line width=2mm, black!30, >=, line cap=round,
      shorten >=1mm, shorten <=1mm]
        \path (1)  edge[out=250, in=110, wavy]         (2);
        \path (1) edge[out=0, in=80, wavy, black!20]   (3);
      \end{scope}
    \end{pgfonlayer}
\end{tikzpicture}
\end{document}

结果:

结果

相关内容