2

How to insert node(arrow) text in the graph of simple necklace layout?

my code:

\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}

Thanks in advace

3
  • I don't fully understand what you mean, do you want to add text along the arrows? Commented Apr 4, 2016 at 11:02
  • @TorbjørnT. Yes, that's what I want :)
    – Mantas
    Commented Apr 4, 2016 at 11:03
  • And one more thing, why some arrows lose their tips, if I everywhere declared that it is ->, not --?
    – Mantas
    Commented Apr 4, 2016 at 11:09

1 Answer 1

3

You can use the syntax from the quotes library to do that. For example, a ->["some text"] b will add some text next to the arrow. You can add options to that label by writing them immediately after the quote, e.g. a ->["some text" {red,draw}] b. I think you need the braces if there is more than one option.

Note that instead of redefining every node I made a style mynode and said nodes={mynode} in the \graph option. Otherwise, the labels for the arrows would be affected as well.

The arrow tips are all there, but they are covered by the lower part of the rectangle split nodes. Modify the filling to rectangle split part fill={none,none} and you'll see that. I don't know how to fix that at the moment.

\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}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .