3

I am trying to create a flowchart and each of the boxes contains two additional boxes, a white box on the top left and a white box on the top right with the block number.

Flow Chart Design

Is there a way to automate the process of drawing the white boxes when the main box is defined in the \tikzstyle{} declaration? Or do I have to draw them manually for each block? My current workaround is to define the white boxes as nodes and shift them in x-y coordinates to align them where I need them.

Here is my current code:

\documentclass[10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows}
\usepackage[letterpaper, margin=1.0cm,showframe, nohead, nofoot, nomarginpar]{geometry}
\usepackage[default]{lato}

% Define Styles
\tikzstyle{nominal} = [rectangle, minimum width=5.5cm, minimum height=3cm, draw=black, line width=0.5mm, fill=gray!40, text width=50mm]
\tikzstyle{white} = [rectangle, minimum width=0.5cm, minimum height=0.5cm, text centered, draw=black, line width=0.5mm, fill=white]
\tikzstyle{arrow} = [thick, ->, >=stealth]

\begin{document}
\vspace*{1em}

% Tikz Picture
\begin{tikzpicture}[node distance=2cm]

% Input Nodes
\node (1) [nominal ] {\hspace{0.5cm}\textbf{\_\_ / \_\_:\_\_}\newline First block};
\node (2) [nominal, right of=1, xshift=4.5cm] {\hspace{0.5cm}\textbf{\_\_ / \_\_:\_\_}\newline the second block};
\node (3) [nominal, below of=2, yshift=-2.5cm] {\hspace{0.5cm}\textbf{\_\_ / \_\_:\_\_}\newline the third block};

% Draw White boxes
\node (w1_L) [white, below of=1, xshift=-2.5cm, yshift=3.25cm] {};
\node (w1_R) [white, below of=1, xshift=2.5cm, yshift=3.25cm] {1};
\node (w2_L) [white, below of=2, xshift=-2.5cm, yshift=3.25cm] {};
\node (w2_R) [white, below of=2, xshift=2.5cm, yshift=3.25cm] {2};
\node (w3_L) [white, below of=3, xshift=-2.5cm, yshift=3.25cm] {};
\node (w3_R) [white, below of=3, xshift=2.5cm, yshift=3.25cm] {3};

% Draw Arrows
\draw [arrow] (1) -- (2);
\draw [arrow] (1) |- (3);

\end{tikzpicture}

\end{document}
1
  • 1
    Would a macro do? You can hang the white boxes over the main one using 1.north west or similar... – Rmano Nov 13 '17 at 20:22
2

There's no need for special macros joining three nodes or a path picture, this nodes can be drawn like a regular node with two inner labels.

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,positioning}
\begin{document}
\tikzset{nominal/.style = {rectangle, minimum width=5.5cm, 
        minimum height=3cm, draw=black, line width=0.5mm, 
        fill=gray!40, text width=50mm},
    smallwhite/.style = {rectangle, minimum width=0.5cm, minimum height=0.5cm, 
        text centered, draw=black, line width=0.5mm, fill=white},
    arrow/.style = {thick, ->, >=stealth},
}

\begin{tikzpicture}[node distance=2cm and 3cm,
    ]
    \node[nominal, 
        label={[smallwhite, anchor=north east]north east:1}, 
        label={[smallwhite, anchor=north west]north west:A}] (one) {first block};

    \node[nominal, 
        label={[smallwhite, anchor=north east]north east:2}, 
        label={[smallwhite, anchor=north west]north west:B},
        right=of one] (two) {second block};

    \node[nominal, 
        label={[smallwhite, anchor=north east]north east:3}, 
        label={[smallwhite, anchor=north west]north west:C},
        below=of two] (three) {third block};

    \draw [arrow] (one) -- (two);
    \draw [arrow] (one) |- (three);
\end{tikzpicture}
\end{document}

enter image description here

5

i assume that upper left sub node are always empty:

enter image description here

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

\tikzset{
mainnode/.style = {rectangle, draw, line width=0.5mm, fill=gray!40,
                   text width=50mm, minimum height=30mm, inner sep=2.5mm, outer sep=0mm,
                   path picture={    % <-- added
                   \node [subnode, below right=0mm of path picture bounding box.north west] {};
                   \node [subnode, below  left=0mm of path picture bounding box.north east] {#1};
                                }%%
                   },
 subnode/.style = {rectangle, draw, line width=0.5mm, fill=white,
                   minimum height=7mm, text width=5mm, align=center,
                   inner sep=1mm, outer sep=0mm},
   arrow/.style = {thick, -Stealth}
        }

\begin{document}
    \begin{tikzpicture}[
node distance=1cm and 2cm
                        ]
% nodes
\node (n1) [mainnode=1]     {\hspace{0.5cm}\textbf{\_\_ / \_\_:\_\_}\\
                             First block};
\node (n2) [mainnode=2,
            right=of n1]    {\hspace{0.5cm}\textbf{\_\_ / \_\_:\_\_}\\
                             The second block};
\node (n3) [mainnode=3,
            below=of n2]    {\hspace{0.5cm}\textbf{\_\_ / \_\_:\_\_}\\
                             The third block};
% arrows
\draw [arrow] (n1) -- (n2);
\draw [arrow] (n1) |- (n3);
    \end{tikzpicture}
\end{document}

edit: in case that also left top sub node has some text, than you need change definition of mainnode to

mainnode/.style args = {#1/#2}%
        {rectangle, draw, line width=0.5mm, fill=gray!40,
         text width=50mm, minimum height=30mm, inner sep=2.5mm, outer sep=0mm,
         path picture={    % <-- added
         \node [subnode, below right=0mm of path picture bounding box.north west] {#1};
         \node [subnode, below  left=0mm of path picture bounding box.north east] {#2};
                    }%%
       },

and than use style for example as:

    \begin{tikzpicture}[
node distance=1cm and 2cm
                        ]
% nodes
\node (n1) [mainnode= /1]     {\hspace{0.5cm}\textbf{\_\_ / \_\_:\_\_}\\
                             First block};
\node (n2) [mainnode= /2,
            right=of n1]    {\hspace{0.5cm}\textbf{\_\_ / \_\_:\_\_}\\
                             The second block};
\node (n3) [mainnode=C/3,
            below=of n2]    {\hspace{0.5cm}\textbf{\_\_ / \_\_:\_\_}\\
                             The third block};
% arrows
\draw [arrow] (n1) -- (n2);
\draw [arrow] (n1) |- (n3);
    \end{tikzpicture}

and you will obtain:

enter image description here

2

Well, @Zarko solution is better... but this is another one with a simple macro.

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,positioning}
\begin{document}
\tikzset{nominal/.style = {rectangle, minimum width=5.5cm, 
        minimum height=3cm, draw=black, line width=0.5mm, 
        fill=gray!40, text width=50mm},
    smallwhite/.style = {rectangle, minimum width=0.5cm, minimum height=0.5cm, 
        text centered, draw=black, line width=0.5mm, fill=white},
    arrow/.style = {thick, ->, >=stealth},
}
\newcommand{\pnominal}[5][]{%
    \node (#2) [nominal, #1] {#3}; 
    \node at (#2.north east) (#2-left) [smallwhite, anchor = north east] {#4}; 
    \node at (#2.north west) (#2-right) [smallwhite, anchor = north west] {#5}; 
}
\begin{tikzpicture}[node distance=2cm and 3cm,
    ]
    \pnominal[]{one}{first block}{A}{1}
    \pnominal[right= of one]{two}{second block}{B}{2}
    \pnominal[below= of two]{three}{third block}{C}{3}

    \draw [arrow] (one) -- (two);
    \draw [arrow] (one) |- (three);
\end{tikzpicture}
\end{document}

enter image description here

1
  • 1
    apparently you are wrong, which answer is better (according to op choose) :-) – Zarko Nov 13 '17 at 21:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.