项链布局字符串(节点)文本插入

项链布局字符串(节点)文本插入

如何在简单项链布局图中插入节点(箭头)文本?

我的代码:

\documentclass{article}


\usepackage{tikz}
\usetikzlibrary{quotes}
\usetikzlibrary{shapes}
\usetikzlibrary{graphdrawing}
\usetikzlibrary{graphs}
\usegdlibrary{trees}
\usegdlibrary{circular}
\begin{document}
\begin{tikzpicture}[>=stealth, every node/.style={rectangle,rectangle split, rectangle split parts=2,rectangle split part fill={red!30,white!20}, draw, minimum size=0.75cm}, node sep=3cm]
\graph [simple necklace layout]
    {

        Start,Hangup,Cancel Sms,Init1,Idle,SendSms1,TestModem,SendSms2,SendSms3;
  Start->Init1-> Idle;3 ->[xshift=3pt,yshift=-2pt]1 -> 2;
  3 -> 5 -> 6 ->[xshift=-1pt,yshift=-2pt] 4 ->[xshift=1pt,yshift=-2pt]5, 5 ->[xshift=-1pt,yshift=2pt] 4 ->[xshift=1pt,yshift=2pt] 6;

    };


\end{tikzpicture}
\end{document}

提前致谢

答案1

您可以使用库中的语法quotes来执行此操作。例如,a ->["some text"] b将添加一些文字箭头旁边。您可以通过在引号后立即写下选项来向该标签添加选项,例如a ->["some text" {red,draw}] b。如果有多个选项,我认为您需要括号。

请注意,我没有重新定义,而是every node创建了一种样式mynodenodes={mynode}\graph选项中说明。否则,箭头的标签也会受到影响。

箭头都在,但是被rectangle split节点的下半部分遮住了。修改填充rectangle split part fill={none,none},你就会看到。目前我不知道如何修复它。

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{quotes,arrows.meta}
\usetikzlibrary{shapes}
\usetikzlibrary{graphdrawing}
\usetikzlibrary{graphs}
\usegdlibrary{trees}
\usegdlibrary{circular}
\begin{document}
\begin{tikzpicture}[
  >=Stealth,
  mynode/.style={
     rectangle,
     rectangle split,
     rectangle split parts=2,
     rectangle split part fill={red!30,white!20},
     draw, 
     minimum size=0.75cm},
  node sep=1cm]
\graph [
  simple necklace layout,nodes={mynode},
]
    {
     Start,
     Hangup,
     Cancel Sms,
     Init1,
     Idle,
     SendSms1,
     TestModem,
     SendSms2,
     SendSms3;
     Start->["Some text" {sloped,pos=0.6}]
        Init1->["relax" {sloped,below}]
        Idle;
     3 ->[xshift=3pt,yshift=-2pt]
        1 -> 2;
     3 -> 
         5 -> 
         6 ->[xshift=-1pt,yshift=-2pt] 
         4 ->[xshift=1pt,yshift=-2pt] 5; 
     5 ->[xshift=-1pt,yshift=2pt]
         4 ->[xshift=1pt,yshift=2pt,"abc"]
         6;
    };
\end{tikzpicture}
\end{document}

相关内容