1

I want to create nested node in tikz but meet difficult to align

Here is the code

\documentclass[12pt, a4paper, oneside]{standalone} 
\usepackage{algorithm2e}
\usepackage{pdfpages}
\usepackage{listings}
\usepackage{parcolumns}
\usepackage{enumerate}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% DRAWING PETRI NETS & DIAGRAMS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{pgf}
\usepackage{tikz}
\usepackage{makecell}
\usetikzlibrary{arrows,shapes,automata,petri,positioning,calc,fit,backgrounds,shapes.arrows,shapes.geometric,chains,matrix}
\tikzset{
    data/.style={
        ellipse,
        thick,
        draw=black,
        minimum width = 2cm,
    },
    place/.style={
        circle,
        thick,
        draw=blue,
        fill=blue!20,
        minimum size=6mm,
    },
    transition/.style={
        rectangle,
        thick,
        draw=black,
        fill=black!50,
        minimum size=6mm
    },
    transitionH/.style={
        rectangle,
        thick,
        fill=black,
        minimum width=6mm,
        minimum height=2mm
    },
    transitionHW/.style={
        rectangle,
        thick,
        draw=black,
        minimum width=6mm,
        minimum height=2mm
    },
    transitionV/.style={
        rectangle,
        thick,
        fill=black,
        minimum width=2mm,
        minimum height=6mm
    },
    transitionVW/.style={
        rectangle,
        thick,
        draw=black,
        minimum width=2mm,
        minimum height=6mm
    },
    terminal/.style={
        rounded rectangle,
        thick,
        draw=black
    },
    status/.style={
        circle,
        thick,
        draw=black,
        minimum size=15mm
    },
    decision/.style={
        diamond,
        aspect = 2,
        thick,
        draw=black
    },
    block/.style={
        rectangle,
        thick,
        draw=black,
        minimum width = 2cm,
        rounded corners
    },
    borderE/.style={
        ellipse,
        thick,
        draw=black
    },
    borderRd/.style={
        rectangle,
        thick,
        draw=gray,
        dashed,
        rounded corners= 5mm
    },
    %double arrow
    arrowD/.style={
        double arrow,
        fill = black,
        double arrow head extend=1mm,
        double arrow head indent =.5mm,
        minimum width=3mm,
        minimum height=7mm,
        inner ysep=0.5mm
    }
}     

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% VIETNAMESE MACROS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%\usepackage[vietnam]{babel}
\usepackage[utf8]{vietnam}

\begin{document}
        %if need link to inside, use ``remember picture''
    \begin{tikzpicture}[node distance=1cm,>=stealth',bend angle=25,auto,initial text={}]
        \node [data,initial] (M0) {
            \begin{tikzpicture}[auto]
                \node (m0) {\begin{tabular}{c} $M_0$ \\ \_ \\ \_ \end{tabular}};
                \node [data, right= of m0] (A1B1C1) {$A_1B_1C_1$};
            \end{tikzpicture}
        };      

        \node [data, below= of M0] (M1) {
            \begin{tikzpicture}[auto]
                \node (m1) {\begin{tabular}{c} $M_1$ \\ loop \\ \_ \end{tabular}};
                \node [data,initial, right=of m1] (A2B2C1) {$A_2B_2C_1$}
                    edge[in=-5,out=5,loop right] node {$t_B$} ();                    
                \node [data, below=of A2B2C1] (A3B2C1) {$A_3B_2C_1$}
                    edge[loop right] node {$t_B$} ()
                    edge[pre] node {$t_A$} (A2B2C1);
            \end{tikzpicture}
        }  
            edge [pre]  node {$F_1$} (M0);
    \end{tikzpicture}  

\end{document}

With result as below

enter image description here

As you see that:

  1. Inside the second node, the M1 \\ loop \\ _ does not in center veritcally, or, at least, align at top. I know I can use yshift=-a cm. But I hate the hardcode like that. Is there another way?

  2. Can we align the drawing inside 2 nodes vertically?

  3. Label tA and tB is a little bit faraway while label F1 distance is acceptable

Basically, in my diagram, each node has 2 separate modules: Attributes on the left, A small automata on the right. Big Nodes are also linked each others

I was confused about the right way to draw this. Do you have other solutions for this.

2
  • 1
    Nesting tikzpictures rarely works well (search on this site). Would a solution that avoided that be acceptable? Commented Jun 21, 2014 at 14:09
  • @LoopSpace Yes, I am finding another solution for draw nested automata/workflow (each node of automata is an automata/workflow, I dont know how it called). If you have any solution, please help.
    – thuanle
    Commented Jun 21, 2014 at 14:34

1 Answer 1

2

This is one possible improvement.

  1. Center of m1 loop is done by putting node (A2B2C1) to the right of m1.north east

  2. Alignment of 2 nodes is adjusted via relative to node (mo) and (m1), respectively.

  3. Label issue is tackled by using label inside the node option

    label={[label distance=0.5cm] right:$t_B$}

enter image description here

Code

\documentclass[12pt, a4paper, oneside,border=10pt]{standalone} 
\usepackage{algorithm2e}
\usepackage{pdfpages}
\usepackage{listings}
\usepackage{parcolumns}
\usepackage{enumerate}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% DRAWING PETRI NETS & DIAGRAMS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{pgf}
\usepackage{tikz}
\usepackage{makecell}
\usetikzlibrary{arrows,shapes,automata,petri,positioning,calc,fit,backgrounds,shapes.arrows,shapes.geometric,chains,matrix}
\tikzset{
    data/.style={
        ellipse,
        thick,
        draw=black,
        minimum width = 2cm,
    },
    place/.style={
        circle,
        thick,
        draw=blue,
        fill=blue!20,
        minimum size=6mm,
    },
    transition/.style={
        rectangle,
        thick,
        draw=black,
        fill=black!50,
        minimum size=6mm
    },
    transitionH/.style={
        rectangle,
        thick,
        fill=black,
        minimum width=6mm,
        minimum height=2mm
    },
    transitionHW/.style={
        rectangle,
        thick,
        draw=black,
        minimum width=6mm,
        minimum height=2mm
    },
    transitionV/.style={
        rectangle,
        thick,
        fill=black,
        minimum width=2mm,
        minimum height=6mm
    },
    transitionVW/.style={
        rectangle,
        thick,
        draw=black,
        minimum width=2mm,
        minimum height=6mm
    },
    terminal/.style={
        rounded rectangle,
        thick,
        draw=black
    },
    status/.style={
        circle,
        thick,
        draw=black,
        minimum size=15mm
    },
    decision/.style={
        diamond,
        aspect = 2,
        thick,
        draw=black
    },
    block/.style={
        rectangle,
        thick,
        draw=black,
        minimum width = 2cm,
        rounded corners
    },
    borderE/.style={
        ellipse,
        thick,
        draw=black
    },
    borderRd/.style={
        rectangle,
        thick,
        draw=gray,
        dashed,
        rounded corners= 5mm
    },
    %double arrow
    arrowD/.style={
        double arrow,
        fill = black,
        double arrow head extend=1mm,
        double arrow head indent =.5mm,
        minimum width=3mm,
        minimum height=7mm,
        inner ysep=0.5mm
    }
}     

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% VIETNAMESE MACROS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%\usepackage[vietnam]{babel}
\usepackage[utf8]{vietnam}

\begin{document}
        %if need link to inside, use ``remember picture''
    \begin{tikzpicture}[node distance=1cm,>=stealth',bend angle=25,auto,initial text={}]
        \node [data,initial] (M0) {
            \begin{tikzpicture}[auto]
                \node (m0) {\begin{tabular}{c} $M_0$ \\ \_ \\ \_ \end{tabular}};
                \node [data, right= of m0.center] (A1B1C1) {$A_1B_1C_1$};
            \end{tikzpicture}
        };      
        \node [data, below= of M0] (M1) {
            \begin{tikzpicture}[auto]
                \node (m1) {\begin{tabular}{c} $M_1$ \\ loop \\ \_ \end{tabular}};
                \node [data,initial, right= of m1.north east, label={[label distance=0.5cm] right:$t_B$}] (A2B2C1) {$A_2B_2C_1$}
                    edge[in=-5,out=5,loop right] ();                    
                \node [data, below=of A2B2C1, label={[label distance=0.5cm] right:$t_B$}] (A3B2C1) {$A_3B_2C_1$}
                    edge[loop right] ()
                    edge[pre] (A2B2C1);
                \node[] at ($(A2B2C1)!0.3!(A3B2C1)+(-0.4cm,0)$) {$t_A$};
            \end{tikzpicture}
        }  
            edge [pre]  node {$F_1$} (M0);
    \end{tikzpicture}  

\end{document}
1
  • Thanks for your help. But tB is the label of the loop. So, I dont refer using distance like that. I will try apply that approach to loop
    – thuanle
    Commented Jun 21, 2014 at 16:02

You must log in to answer this question.

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