1

I am trying to draw a statemachine, in which some states are associated to one application, and the other one to another one.. I want to illustrate in my tikz drawing, by using different color but can't seem to make it work..

\documentclass[11pt,twoside]{article}

% ------- Enable UTF8 characters ------- %
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows,shadows,shadows.blur,positioning,calc,arrows.meta,automata}
\usetikzlibrary{matrix,calc,decorations.pathreplacing}

\begin{document}

    \begin{figure}[H]
        \centering
        \begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=2.8cm,
            semithick]
            \tikzstyle{every state}=[fill=black,draw=none,text=white]
            \tikzstyle{every sub}=[fill=red,draw=none,text=white]
            \node[state] (A)              {State i};
            \node (middle) [right = 1.5 cm of A] {h};
            \node[state] (B) [right = 3 cm of A] {State j};
            \node[sub] (i_1) [above = 1cm of middle ] {$i_1$};

            \path (A) edge [bend left]  node {$P_{ij}$} (B)
                  (B) edge [bend left] node {$P_{ji}$} (A)
                  (A) edge [loop above] node {$P_{ii}$} (A)             
                  (B) edge [loop above] node {$P_{jj}$} (B);
        \end{tikzpicture}        
    \end{figure}

\end{document}

What i thought would work is to add a local

\tikzstyle{every sub}=[fill=red,draw=none,text=white]

Which i could use when i wan't to draw states associated with the other application, but it seems like tikz does not like it, why though?

  • 1
    Use \tikzstyle{sub} instead of \tikzstyle{every sub}. – Jasper Habicht Sep 15 '17 at 17:09
2

like this?

enter image description here

\documentclass[11pt,twoside]{article}

% ------- Enable UTF8 characters ------- %
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{tikz}
\usetikzlibrary{arrows.meta, automata, positioning, quotes}

\usepackage[floats,active,tightpage]{preview}
\setlength\PreviewBorder{1em}


    \begin{document}
\begin{figure}[ht]
    \centering
    \begin{tikzpicture}[auto,
node distance = 12mm and 12mm,
    shorten > = 1pt,
            > = Stealth,
                semithick,
 state/.style = {circle, fill=#1, draw=none,
                 inner sep=1mm, text=white},
 state/.default = black
                        ]
\node (A) [state]               {State i};
\node (M) [right=of A]          {h};
\node (B) [state, right=of M]   {State j};
\node (I) [state=red,above=of M]{$i_1$};
%
\path[->]   (A) edge [bend left,  "$P_{ij}$"]   (B)
            (B) edge [bend left,  "$P_{ji}$"]   (A)
            (A) edge [loop above, "$P_{ii}$"]   (A)
            (B) edge [loop above, "$P_{jj}$"]   (B);
    \end{tikzpicture}
\end{figure}
    \end{document}

in mwe i preserve from yours only for this picture relevant libraries. note: \tikstyle is depreciate tikz syntax. instead it use \tikzset{...} or definetikzpicture` elements style as its options as is done in mwe above.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.