使用 tikzstyle 建立子流程框

使用 tikzstyle 建立子流程框

我發現本指南介紹如何使用 tizk 製作流程圖,但子進程框沒有選項。

我怎麼能創造一個像這樣的盒子,並在裡面的兩行之間寫字? 子行程符號

先致謝! :)

編輯: 到目前為止,我得到的最接近的是

\tikzstyle{subprocess} = [rectangle, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=orange!30, double distance=

\node (subpro1) [subprocess, below of=start] {Failed subprocess box};

但這會產生 2 行每一個邊,而我只想在兩個垂直邊上有雙線。它還將彩色背景僅放在裡面,而我希望它放在最外面的矩形上。

在此輸入影像描述

答案1

在此輸入影像描述

\documentclass[tikz, margin=3mm]{standalone}
     \newcommand\ppbb{path picture bounding box}

\begin{document}
    \begin{tikzpicture}[ 
subprocess/.style = {rectangle, draw=black, fill=orange!30,
                     minimum width=3cm, minimum height=1cm,inner xsep=3mm,
                     text width =\pgfkeysvalueof{/pgf/minimum width}-2*\pgfkeysvalueof{/pgf/inner xsep},
                     align=flush center,
                     path picture={\draw 
    ([xshift =2mm] \ppbb.north west) -- ([xshift= 2mm] \ppbb.south west)
    ([xshift=-2mm] \ppbb.north east) -- ([xshift=-2mm] \ppbb.south east);
                                  },% end of path picture
                    }
                      ]
\node (subpro1) [subprocess] {Failed subprocess box};
    \end{tikzpicture}
\end{document}

附錄(1):subprocess您可以附上的 樣式\tikzset如下:

\tikzset{
    subprocess/.style = {rectangle, draw=black, fill=orange!30,
                         minimum width=3cm, minimum height=1cm, inner xsep=3mm,
                         text width =\pgfkeysvalueof{/pgf/minimum width}-2*\pgfkeysvalueof{/pgf/inner xsep},
                         align=flush center,
                         path picture={\draw 
        ([xshift =2mm] \ppbb.north west) -- ([xshift= 2mm] \ppbb.south west)
        ([xshift=-2mm] \ppbb.north east) -- ([xshift=-2mm] \ppbb.south east);
                                      },% end of path picture
                        }
}

並將其放在文件的序言中。

附錄(2): 如果您希望僅在一行上顯示文本,則程式碼subprocess可以簡化為:

\documentclass[tikz, margin=3mm]{standalone}
     \newcommand\ppbb{path picture bounding box}
\tikzset{
subprocess/.style = {rectangle, draw=black, fill=orange!30,
                     minimum width=3cm, minimum height=1cm, inner xsep=3mm,
                     align=flush center,
                     path picture={\draw
    ([xshift =2mm] \ppbb.north west) -- ([xshift= 2mm] \ppbb.south west)
    ([xshift=-2mm] \ppbb.north east) -- ([xshift=-2mm] \ppbb.south east);
                                  },% end of path picture
                    }
        }% end of tikzset

\begin{document}
    \begin{tikzpicture}
\node (subpro1) [subprocess] {Failed subprocess box};
    \end{tikzpicture}
\end{document}

在此輸入影像描述

附錄(3): 如果您希望手動指定形狀的“最小/最大寬度”,那麼以下範例可能可以幫助您:

\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{positioning}

     \newcommand\ppbb{path picture bounding box}
\tikzset{
subprocess/.style = {rectangle, draw=black, semithick, fill=orange!30,
                     minimum width=#1, minimum height=1cm, inner xsep=3mm, % <-- changed
                     text width =\pgfkeysvalueof{/pgf/minimum width}-2*\pgfkeysvalueof{/pgf/inner xsep},
                     align=flush center,
                     path picture={\draw
    ([xshift =2mm] \ppbb.north west) -- ([xshift= 2mm] \ppbb.south west)
    ([xshift=-2mm] \ppbb.north east) -- ([xshift=-2mm] \ppbb.south east);
                                  },% end of path picture
                    },
subprocess/.default = 24mm % <-- added 
        }% end of tikzset

\begin{document}
    \begin{tikzpicture}
\node (subpro1) [subprocess] {subprocess};% <-- use default width
\node (subpro2) [subprocess=33mm, below=of subpro1] {very long subprocess};% <-- use locally prescribed width
\node (subpro3) [subprocess=44mm, below=of subpro2] {very long subprocess};% <-- use locally prescribed width
\draw   (subpro1) edge[->] (subpro2)
        (subpro2) edge[->] (subpro3);
    \end{tikzpicture}
\end{document}

在此輸入影像描述

相關內容