0

Hi i want to add the box description into my flowchart like this. (Sorry for bad drawing).

first, i don't know how to make that box and shapes inside it and aligned in equal symbol. The box should be about 5x6cm (flexible). And i want the flowchart have caption just below the flowchart.

This is my attempt for the flowchart only:

\documentclass{book}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows}
\usepackage{caption}

\tikzstyle{startstop} = [rectangle, rounded corners, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=red!30] \tikzstyle{io}=[trapezium, trapezium left angle=70, trapezium right angle=110, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=blue!30] \tikzstyle{process} = [rectangle, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=orange!30] \tikzstyle{decision} = [diamond, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=green!30] \tikzstyle{arrow} = [thick,->,>=stealth] \tikzstyle{line} = [draw, very thick, color=black!50, -latex']

\begin{document} \begin{tikzpicture}[node distance=2cm] \node(start)[startstop]{Start}; \node(in1)[io, below of=start]{Input}; \node(pro1)[process, below of=in1]{Process 1}; \node(dec1)[decision, below of=pro1, yshift=-0.5cm]{Decision 1}; \node(pro2a)[process, below of=dec1, yshift=-0.5cm]{Process 2a}; \node(pro2b)[process, right of=dec1, xshift=2cm]{Process 2b}; \node(out1)[io, below of=pro2a]{Output}; \node(stop)[startstop, below of=out1]{Stop};

    \draw[arrow](start)--(in1);
    \draw[arrow](in1)--(pro1);
    \draw[arrow](pro1)--(dec1);
    \draw[arrow](dec1)--node[anchor=east]{yes}(pro2a);
    \draw[arrow](dec1)--node[anchor=south]{no}(pro2b);
    \path[line, dashed](pro2b) |- (pro1);
    \draw[arrow](pro2a)--(out1);
    \path[line](out1)--(stop);

\end{tikzpicture}   

\end{document}

Please help me. Thanks in advance.

2 Answers2

2

The most of effort I gives to off-topic issues. Idea, how to add legend is stolen from @js bibra answer (+1) and slightly upgraded for better match to your sketch:

\documentclass{book}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
                chains,
                matrix,
                positioning,
                quotes,
                shapes.geometric}
\usepackage{array}
\usepackage{caption}

\tikzset{FlowChart/.style = { base/.style = {draw, minimum width=32mm, minimum height=8mm, align=center}, startstop/.style = {base, rectangle, rounded corners, fill=red!30}, process/.style = {base, rectangle, fill=orange!30}, io/.style = {base, trapezium, trapezium stretches, trapezium left angle=70, trapezium right angle=110, fill=blue!30}, decision/.style = {base, diamond, aspect=1.3, fill=green!30, inner xsep=1pt}, arr/.style = {-Stealth, semithick} } }% end of tikzset

\begin{document} \begin{figure}[htb] \centering \begin{tikzpicture}[FlowChart, node distance = 6mm and 12mm, start chain = A going below, ] \begin{scope}[every node/.append style={on chain=A, join=by arr}] \node [startstop] {Start}; % A-1 \node [io] {Input}; \node [process] {Process 1}; % A-3 \node [decision] {Decision 1}; % A-4 \node [process] {Process 2a};
\node [io] {Output}; \node [startstop] {Stop}; % A-7 \end{scope} \node (A-8) [process, right=of A-4] {Process 2b}; % \draw[arr] (A-4) to ["yes"] (A-8); \path (A-4) to ["no"] (A-5); \draw[arr, dashed] (A-8) |- (A-3); % \matrix (m) [draw, below right=0mm of A-1.north -| A-8.east, matrix of nodes, column 1/.style = {every node/.append style={scale=0.25, anchor=south}}, column sep = 1em ] { & {} \ & {} \ \draw[arr] (-.3,0) -- (0.3,0); & bla bla \ \draw[arr, dashed] (-.3,0) -- (0.3,0); & bla bla \ |[startstop]| & bla bla \ |[io]| & bla bla \ |[process]| & bla bla \ |[decision]| & bla bla \ }; \node[below] at (m.north) {Description:}; \end{tikzpicture} \caption{Flowchart} \label{fig:flowchart} \end{figure} \end{document}

Note: tizstyle is deprecated, use tikzset instead it as in above MWE (Minimal Working Example).

enter image description here

Zarko
  • 296,517
1

I have only drawn the first two nodes and the legend on right -- the sam has been adapted from --

Same tikz. Two matrices. (Diagram legend)

enter image description here

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{
    positioning,
    calc,
    shapes.geometric,
    matrix}

\begin{document}

\begin{tikzpicture}[ line/.style={ draw, thick, -latex }, status/.style={ rectangle, rounded corners, draw=black, text centered, anchor=north, text=black, minimum width=2em, minimum height=2em }, trapezium/.style={ trapezium,trapezium left angle=70,trapezium left angle=110, draw=black, text centered, anchor=north, text=black, minimum width=2em, minimum height=2em }, m2style/.style={ column sep=1em, row sep=1em, nodes={status}, font=\bfseries }, mstyle/.style={ column sep=10em, row sep=3em, nodes={status}, font=\bfseries } ]

\matrix (m) [ matrix of nodes, ampersand replacement=&, mstyle, row 1 column 1/.style={nodes={fill=green!30}}, row 2 column 1/.style={nodes={fill=blue!30}}, ]{ A\ B\ };

\matrix (m2) [ right=1.8cm of m, draw=black, matrix of nodes, ampersand replacement=&, m2style, column 2/.append style={nodes={text width=1.5cm}}, ]{ |[fill=green]|H & Healthy \ |[fill=red]|A1 & Infected \ |[fill=yellow]|A2 & Infected \ |[fill=gray]|D & Death \ };

\draw[line] (m-1-1) -- (m-2-1) node[pos=0.5,left,align=left] {label1}; %\draw[line] (m-1-2) -- (m-1-3) node[pos=0.5,above] {wait $\tau$ ticks}; %\draw[line] (m-1-3) -- (m-2-3) node[pos=0.5,right] {wait 1 tick}; %\draw[line] (m-2-3) -- (m-2-2) node[pos=0.5,above] {$p_\mathrm{replenished}$}; %\draw[line] (m-2-2) -| (m-1-1) node[pos=0.2,above] {$1-p_\mathrm{infected}$}; %\draw[line] (m-2-2) -- (m-1-2) node[pos=0.5,left] {$p_\mathrm{infected}$};

\path let \p1=(m2.east), \p2=(m2.west) in node[align=center,text width=\x1-\x2,anchor=south,inner sep=0pt] at ([yshift=5pt]m2.north) {Description}; \end{tikzpicture}

\end{document}

js bibra
  • 21,280