3

This is what I need:

enter image description here

Here is what I've just ended up with:

enter image description here

\documentclass[border = 2pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{automata,positioning,fit}

\begin{document}
    \begin{tikzpicture}
        \node[] (B) at (0,1) {B};
        \node[state, initial text=, initial below, accepting] (initial) {\textbf{0}};
        \node[right=of initial.south, yshift=-5mm, xshift=3mm] (B1) {
            \begin{tikzpicture}
            \node[state] (10) {$b_{10}$};
            \node[state] (11) [below=of 10] {$b_{11}$};
            \begin{scope}[every node/.style={scale=.7}]
                \path[->] 
                (10) edge [bend right] node  {$\beta_{11}$} (11)    
                (11) edge [bend right] node  {$\alpha_{21}$} (10);
            \end{scope}
            \end{tikzpicture}};
        \node[right=of B1, yshift=-0mm] (B2) {
            \begin{tikzpicture}
            \node[state] (20) {$b_{20}$};
            \node[state] (21) [below=of 20] {$b_{21}$};
            \begin{scope}[every node/.style={scale=.7}]
            \path[->] 
            (20) edge [bend right] node  {$\beta_{21}$} (21)    
            (21) edge [bend right] node  {$\alpha_{22}$} (20);
            \end{scope}
            \end{tikzpicture}};
        \node[draw,dashed,fit=(B1)] {};
        \node[draw,dashed,fit=(B2)] {};
        \node[draw,fit=(B)(B1)(B2), inner sep=3mm] {};
    \end{tikzpicture}
\end{document}

I could not handle the red edges with remember picture as suggested here.

Additionally, [swap] does not work saying:

(21) edge [bend right] node[swap] {$\alpha_{22}$} (20);

Update :

According to @cfr's advice, I designed the sketch with a different approach using savebox/usebox, instead of nested tikzpictures as follows:

\documentclass[border = 2pt]{standalone}

\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{automata,positioning,fit}

\newsavebox\BB
\savebox{\BB}{
    \begin{tikzpicture}
    \node[state] (10) {$b_{10}$};
    \node[state] (11) [below=of 10] {$b_{11}$};
    \begin{scope}[every node/.style={scale=.7}]
    \path[->] 
    (10) edge [bend right] node {$\beta_{11}$} (11) 
    (11) edge [bend right] node  {$\alpha_{21}$} (10);
    \end{scope}
    \end{tikzpicture}}

\newsavebox\CC
\savebox{\CC}{
    \begin{tikzpicture}
    \node[state] (20) {$b_{20}$};
    \node[state] (21) [below=of 20] {$b_{21}$};
    \begin{scope}[every node/.style={scale=.7}]
    \path[->] 
    (20) edge [bend right] node  {$\beta_{21}$} (21)    
    (21) edge [bend right] node {$\alpha_{22}$} (20);
    \end{scope}
    \end{tikzpicture}}

\begin{document}
    \begin{tikzpicture}
        \node[] (B) at (0,1) {B};
        \node[state, initial text=, initial below, accepting] (initial) {\textbf{0}};
        \node[right=of initial.south, yshift=-5mm, xshift=3mm] (B1) {
            \usebox{\BB}};
        \node[right=of B1, yshift=-0mm] (B2) {
            \usebox{\CC}};
        \node[draw,dashed,fit=(B1)] {};
        \node[draw,dashed,fit=(B2)] {};
        \node[draw,fit=(B)(B1)(B2), inner sep=3mm] {};
    \end{tikzpicture}
\end{document}
  • 1
    Nesting tikzpictures is not supported and is not expected to work. – cfr Dec 19 '17 at 00:21
  • @cfr: Please check the update. –  Dec 19 '17 at 00:34
  • I would use scopes instead. I think it is easier, but boxes will avoid the problems with nesting, indeed. I'm not sure how well remember picture works in that case, but you can obviously try it. – cfr Dec 19 '17 at 00:41

1 Answers1

3

Never nest tikzpicture environments. In simple cases, it may work if you are lucky, but it is unsupported and, if it later breaks, you get to keep all the itsy-bitsy little pieces.

Scopes can, however, be used in a similar way. For example,

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{automata,positioning,fit,quotes}
\begin{document}
\begin{tikzpicture}
  \node[] (B) at (0,1) {B};
  \node[state, initial text=, initial below, accepting] (initial) {\textbf{0}};
  \begin{scope}[local bounding box=B1, shift=(initial.west), xshift=25mm]
    \node[state] (10) {$b_{10}$};
    \node[state] (11) [below=of 10] {$b_{11}$};
    \begin{scope}[every node/.style={scale=.7}]
      \path[->] 
      (10) edge [bend right] node [left]  {$\beta_{11}$} (11)    
      (11) edge [bend right] node [right]  {$\alpha_{21}$} (10);
    \end{scope}
  \end{scope}
  \begin{scope}[local bounding box=B2,  shift=(B1.west |- initial), xshift=35mm]
    \node[state] (20) {$b_{20}$};
    \node[state] (21) [below=of 20] {$b_{21}$};
    \begin{scope}[every node/.style={scale=.7}]
      \path[->] 
      (20) edge [bend right] node [left]  {$\beta_{21}$} (21)    
      (21) edge [bend right] node [right]  {$\alpha_{22}$} (20);
    \end{scope}
  \end{scope}
  \node[draw,dashed,fit=(B1)] {};
  \node[draw,dashed,fit=(B2)] {};
  \node[draw,fit=(B)(B1)(B2), inner sep=3mm] {};
  \begin{scope}[every edge quotes/.append style={midway, auto}, every edge/.append style={red, ->}]
    \draw (20.north) edge [bend right, "$\kappa$"]  (initial.north);
    \draw (10.north west) edge [bend right, "$\delta$"'] (initial.north east);
    \draw (initial.east) edge ["$\gamma$"'] (10.west);
    \draw (10) edge ["$\alpha$"]  (20);
    \draw (11) edge ["$\beta$"]  (20);
  \end{scope}
\end{tikzpicture}
\end{document}

scope connections

cfr
  • 198,882