TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to generate hidden markov models using tikz. I have successfully generated nodes and connected them. But i want to generate dashed lines generating below the node to an empty space like this enter image description here. I tried to make it work using this code:

\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=2.8cm,
                semithick,scale=1.5,transform shape]
\tikzstyle{every state}=[fill=red,draw=none,text=white]

\node[state]    (A)                    {$S_1$};
\node[state]    (B) [right of=A]       {$S_2$};


\path (A) edge [loop above] node {$a_{11}$} (A)
          edge [bend left]  node {$a_{12}$} (B)
      (B) edge [loop above] node {$a_{22}$} (B)
          edge [bend left]  node {$a_{21}$} (A);

\draw [dashed] (A) edge [bend below] node {$b_{11}$};
\end{tikzpicture}

But this code doesn't work for me. It generates something like thisenter image description here How do i draw dashed lines from the nodes exactly shown in the figure with nodes rainy and sunny?

share|improve this question
    
Welcome to TeX.SX! – Heiko Oberdiek 12 hours ago
    
@Sigur i tried something like this \draw [dashed] (A.west) edge node {$b_{11}$} (A.center) but didn't work. – MarKS 12 hours ago
    
@Sigur did this \draw [dashed] (A.west) node {$b_{11}$} (A.center);. I could see b11 but this time there was no dashed line. – MarKS 12 hours ago
    
Oh, sorry, now I understand what you wish. See answer by @HeikoOberdiek. – Sigur 12 hours ago
up vote 5 down vote accepted

Like this? The labels are not precise, you can change the labels to whatever you want.

enter image description here

\documentclass[border=2mm,tikz]{standalone}
\usetikzlibrary{arrows,automata,positioning}
\begin{document}

\begin{tikzpicture}[->,>=stealth',shorten >=1pt,node distance=2.8cm,
                semithick,scale=1.5,transform shape]
\tikzstyle{every state}=[fill=red,draw=none,text=white]

\node[state]    (A)                    {$S_1$};
\node[state]    (B) [right of=A]       {$S_2$};


\path[auto] (A) edge [loop above] node {$a_{11}$} (A)
          edge [bend left]  node {$a_{12}$} (B)
      (B) edge [loop above] node {$a_{22}$} (B)
          edge [bend left]  node {$a_{21}$} (A);

\node (01) at ([shift={(-3em,-4em)}]A.south) {$b12$};
\node (04) at ([shift={(0,-5em)}]A.south) {$b11$};
\node (05) at ([shift={(3em,-4em)}]A.south) {$b13$};

\draw [shorten >=0pt,dashed] (A.south) --node[pos=.7,fill=white,inner sep=1pt]{0.4} (04);
\draw [shorten >=0pt,dashed] (A.south) --node[fill=white,inner sep=1pt]{0.1} (01);
\draw [shorten >=0pt,dashed] (A.south) --node[fill=white,inner sep=1pt]{0.5} (05);

\end{tikzpicture}

\end{document}
share|improve this answer
    
thank you so much @AboAmmar it worked perfectly. I need to go through how the code works but it was really helpful. – MarKS 11 hours ago

The following example positions the node with $b_{11}$ below A.south and adds a dashed vector between A.south and the previously created node.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows}
\tikzset{state/.style={circle, fill=red,text=white}}
\begin{document}
\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=2.8cm,
                semithick,scale=1.5,transform shape]
\tikzstyle{every state}=[fill=red,draw=none,text=white]

\node[state]    (A)                    {$S_1$};
\node[state]    (B) [right of=A]       {$S_2$};


\path (A) edge [loop above] node {$a_{11}$} (A)
          edge [bend left]  node {$a_{12}$} (B)
      (B) edge [loop above] node {$a_{22}$} (B)
          edge [bend left]  node {$a_{21}$} (A);

\draw[dashed, ->, inner sep=0pt] (A.south) +(-90:2em) node (tmp) {$b_{11}$}
  (A.south) -- (tmp);
\end{tikzpicture}
\end{document}

Result

A more complicate example:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows}
\tikzset{state/.style={circle, fill=red,text=white}}
\begin{document}
\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=2.8cm,
                semithick,scale=1.5,transform shape]
\tikzstyle{every state}=[fill=red,draw=none,text=white]

\node[state]    (A)                    {$S_1$};
\node[state]    (B) [right of=A]       {$S_2$};


\path (A) edge [loop above] node {$a_{11}$} (A)
          edge [bend left]  node {$a_{12}$} (B)
      (B) edge [loop above] node {$a_{22}$} (B)
          edge [bend left]  node {$a_{21}$} (A);

\begin{scope}[densely dashed, ->, inner sep=.2em]
  \draw[shorten >=-2pt]
    (A.south) ++(-90:1.7em) node[font=\scriptsize] (tmp1) {0.4}
              ++(-90:1.8em) node[inner sep=0pt]      (tmp2) {$b_{11}$}
    (A.south) -- (tmp1) -- (tmp2);
  \draw[shorten >=4pt]
    (A.south) ++(-45:1.5em) node[font=\scriptsize] (tmp1) {0.5}
              ++(-45:2em)   node[inner sep=0pt]    (tmp2) {$b_{12}$}
    (A.south) -- (tmp1) -- (tmp2);
  \draw[shorten >=-3pt]
    (A.south) ++(-135:1.5em) node[font=\scriptsize] (tmp1) {0.1}
              ++(-135:2em) node[inner sep=0pt]      (tmp2) {$b_{10}$}
    (A.south) -- (tmp1) -- (tmp2);
\end{scope}
\end{tikzpicture}
\end{document}

Result

share|improve this answer
    
thank you very much @Heiko it works. But i wonder is it possible for b11 to be near the center of the dashed line? And how do i create angle to draw 2 more dashed lines? Unfortunately, i want exactly like shown in the image. – MarKS 11 hours ago
    
i wish i could mark 2 answers but thank you for all the help @HeikoOberdiek. – MarKS 11 hours ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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