在嵌套节点中对齐

在嵌套节点中对齐

我想创建嵌套节点tikz但很难对齐

以下是代码

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

结果如下

在此处输入图片描述

正如你所看到的:

  1. 在第二个节点内,M1 \\ loop \\ _不在垂直居中,或者至少不在顶部对齐。我知道我可以使用yshift=-a cm。但我讨厌这样的硬编码。还有其他方法吗?

  2. 我们可以垂直对齐两个节点内的绘图吗?

  3. 标签tAtB有点远,但标签F1距离可以接受

基本上,在我的图中,每个节点都有 2 个独立的模块:左侧是属性,右侧是小型自动机。大节点也相互链接

我不知道该如何正确绘制。您还有其他解决方案吗?

答案1

这是一种可能的改进。

  1. m1 循环的中心是通过将节点(A2B2C1)放在m1.north east

  2. 2 个节点的对齐分别通过相对于节点 (mo) 和 (m1) 进行调整。

  3. label通过使用节点选项来解决标签问题

    标签={[标签距离=0.5cm]右:$t_B$}

在此处输入图片描述

代码

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

相关内容