控制 tikz 中的边缘形状

控制 tikz 中的边缘形状

我已经使用 tikz 为自动机编写了 latex 代码。我使用 \path 和 \draw 绘制边(参见图 1),并且我希望绘制形状为 (参见图 2) 的边。您知道如何做吗?图1

图 2

提前致谢

编辑:这是我的代码:

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{caption}
\usepackage{subcaption}
% Packages
\usepackage{fixltx2e}
\usepackage{ntheorem}
\usepackage{float}
\usepackage{xr}
\usepackage{geometry}
\usepackage{algpseudocode}
\usepackage{algorithmicx}
\usepackage{algorithm}
\usepackage{caption}
\usepackage{pifont}
\usepackage{verbatim}
\usepackage[english]{babel}
\usepackage{wrapfig}
\usepackage{capt-of}
\usepackage{color}
\usepackage{pdftricks}
\usepackage{etex}
\usepackage[version=0.96]{pgf}
\usepackage{tikz}
\usetikzlibrary {plotmarks,calc,arrows,shapes,snakes,automata,backgrounds,petri,positioning,fit}
\usepackage{proof}
\usepackage{latexsym}
\usepackage{amsfonts}
\usepackage{stackrel}
\usepackage{amsmath}
%\usepackage{amssymb}
%\usepackage{amsthm}
\usepackage{subcaption}

\begin{document}
\begin{figure}[H]
  \centering
\begin{tikzpicture}[->,node distance=1.3cm,>=stealth',bend angle=40,auto,
  place/.style={circle,thick,draw=blue!75,fill=blue!20,minimum size=10mm},
  red place/.style={place,draw=red!75,fill=red!20}
  every label/.style={red},
  every node/.style={scale=.6},
  dots/.style={fill=black,circle,inner sep=2pt},
  initial text={}]

  \node [accepting, place,label={[shift={(0.4,-1.9)}]$x\le850$}] (l1-1)  {$l_1^1$};
  \node [place,right=2cm of l1-1] (l1-2) {$l_2^1$};

  \path (l1-1) edge [in=160,out=190,loop,align=center] node[left]{vp\\$x:=0$} (l1-1)
           edge [in=240,out=210,loop,align=center] node[below,xshift=-7mm]{vs\\
           $x < 850$\\$x:=0$} (l1-1)
           edge [in=140, out=110,loop,align=center] node[above]{ap\\$x \ge 850$
           \\$x:=0$} (l1-1)
    (l1-1) edge node[above]{ats} (l1-2)
    (l1-2) edge [bend right] node[above,align=center]{vp, $x:=0$} (l1-1)
    edge [bend left] node[below,align=center]{vs, $x:=0$} (l1-1);

  \node [accepting, place,right=2cm of l1-2,yshift=1.5cm] (l2-1)  {$l_1^2$};
  \node [place,right=2cm of l2-1,label={[shift={(1.4,-0.9)}]$y\le150$}] (l2-2) {$l_2^2$};
  \node [place,below=2cm of l2-2,label={[shift={(1.4,-0.9)}]$k\le400$}] (l2-3) {$l_3^2$};

  \draw (l2-1) to[in=100,out=90] node[above,align=center] {ats, $y:=0$} (l2-2) ;
  \draw (l2-1) to[in=150,out=40] node[above,align=center] {ap, $y:=0$} (l2-2) ;
  \draw (l2-2) to[in=-20,out=-150] node[below,align=center] {ats, $k:=0$} (l2-1) ;
  \draw (l2-2) to[in=-60,out=-110] node[below,align=center] 
    {ap, $k:=0$\\$y\ge150 \text{ \& } k\ge400$} (l2-1) ;
  \draw [->](l2-2)-- node[right,align=center] {internalp\\ $y\ge150 \text{ \& } k\le400$} (l2-3) ;
  \draw (l2-3) to[in=-90,out=-180] node[above,align=center,xshift=9mm,yshift=-3mm] {vs, $k:=0$}
        (l2-1) ;
  \draw (l2-3) to[in=-110,out=-150] node[below,align=center,xshift=-13mm,yshift=5mm] 
       {vp, $k:=0$\\$k>400$} (l2-1) ;

  \node [accepting, place,below=4cm of l1-1, xshift=-15mm] (l3-1)  {$l_1^3$};
  \node [place,right=1.5cm of l3-1,label={[shift={(0,-1.9)}]$y\le50$}] (l3-2) {$l_2^3$};
  \node [place,right=1.5cm of l3-2,label={[shift={(1.4,-0.9)}]$k\le100$}] (l3-3) {$l_3^3$};
  \node [place,below=1.5cm of l3-3] (l3-4) {$l_4^3$};
  \node [place,below=1.5cm of l3-1] (l3-5) {$l_5^3$};


  \path (l3-1) edge node[below]{vp, $z:=0$} (l3-2)
           edge [bend left] node[above,align=center]{vp, $z:=0$} (l3-2)
           edge node[right]{aget} (l3-5)
    (l3-5) edge [bend left] node[left]{ats} (l3-1)
    (l3-2) edge node[above]{internalp, $z\ge50$} (l3-3)
    (l3-3) edge node[right]{aget} (l3-4)
    (l3-4) edge[bend left] node[left,align=center]{internalp\\ $z\le100$} (l3-3);
  \draw (l3-3) to[in=90,out=90] node[above,align=center] 
       {internalp\\ $z\ge100$} (l3-1) ;

  \node [accepting, place,right=2cm of l3-3] (l4-1)  {$l_1^4$};
  \node [place,right=1.5cm of l4-1,label={[shift={(1.4,-0.9)}]$y\le150$}] (l4-2) {$l_2^4$};
  \node [place,below=1.5cm of l4-1] (l4-3) {$l_3^4$};

  \path (l4-1) edge node[left]{vget} (l4-3)
           edge node[below,align=center]{vp, $t:=0$} (l4-2)
    (l4-2) edge[bend right] node[above]{internalp, $t\ge150$} (l4-1)
    (l4-3) edge node[below,xshift=5mm]{vs, $t:=0$} (l4-2);
\end{tikzpicture}
\caption{enter1 and enter2 form a false-conflict based on timing constraint}\label{fig:fish}
\end{figure}
\end{document}

答案1

rounded corners下面是一个使用直线选项的示例。我定义了一些样式( sh2nsh2se等)来移动节点的中心。

在此处输入图片描述

\documentclass[tikz,margin=5mm]{standalone}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}[node distance=2cm and 2cm]
  \tikzset{
    sh2n/.style={shift={(0,1)}},
    sh2s/.style={shift={(0,-1)}},
    sh2e/.style={shift={(1,0)}},
    sh2w/.style={shift={(-1,0)}},
    %
    sh2nw/.style={shift={(-1,1)}},
    sh2ne/.style={shift={(1,1)}},
    sh2sw/.style={shift={(-1,-1)}},
    sh2se/.style={shift={(1,-1)}},
    %
    rc/.style={rounded corners=2mm,line width=1pt},
    %
    place/.style={draw,circle,fill=cyan!10,inner sep=.5mm,minimum size=5mm},
  }
  \node[place] (a) {a};
  \node[place,left=of a] (b) {b};
  \node[place,above right=of a] (c) {c};

  \draw[-stealth,rc] (a) -- node[above]{a to b} (b);
  \draw[-stealth,rc] (a) |- node[green!50!black,above,pos=.75]{a to c} (c);
  \draw[-stealth,rc] (a) -- ([sh2nw]a.center) -- node[above,red] {a to c (bis)} ([sh2n]b.center) -- (b);
  \draw[-stealth,rc] (b) -- ([sh2se]b.center) -| node[below,blue,pos=.25] {b to c} (c);
\end{tikzpicture}
\end{document}

相关内容