Tikz – How to Create a Double Edged Rectangle for Subroutine Blocks

tikz-pgf

I am trying to define a TikZ node style that comprises three rectangles one after another, as if by the following code:

\documentclass[tikz]{standalone}
\usetikzlibrary{shapes.geometric}
\begin{document}
\begin{tikzpicture}
  \node[draw,
        minimum width=3cm,
        minimum height=1.2cm,
        outer sep=0] (subr) at (0,0) {Subroutine};
  \draw (subr.north west) -- ++(-0.3,0) |- (subr.south west);
  \draw (subr.north east) -- ++(0.3,0) |- (subr.south east);
\end{tikzpicture}
\end{document}

I want to capture all of the above into a single node style like below:

\tikzstyle{subroutine} = {
    draw,
    thick, etc...
    ??? 
}

so I can simply use it as follows:

\begin{tikzpicture}
    \node[subroutine] at (0,0) {Subroutine};
\end{tikzpicture}

Is there any way to do this?
enter image description here

(The grey border is from my document viewer, it is not a part of the actual tikz drawing)

Best Answer

The TikZ's library shapes.multipart does that kind of things.

enter image description here

\documentclass[tikz,border=5mm]{standalone}
\usetikzlibrary{shapes.multipart}
\begin{document}
\begin{tikzpicture}
\tikzset{subroutine/.style={
        rectangle split, rectangle split horizontal,
        rectangle split parts=3, 
        draw, minimum width=3cm,
        minimum height=1.2cm,
        outer sep=0}}   
\path 
(0,0) node[subroutine] {\nodepart{two}subroutine\nodepart{three}}
(0,-1.5) node[subroutine,fill=yellow] {\nodepart{two}routine\nodepart{three}}
;
\end{tikzpicture}
\end{document}

For more details, see Section 71.6. Shapes with Multiple Text Parts in the pgfmanual.

enter image description here