[Tex/LaTex] Adjust the size of fit nodes in tikz


I have a problem with controlling the size of fit nodes in tikzpicture. I want the fit node to cover all the area but it does not seem to be working. I searched around but I have not found the solution yet. I would like to ask for your help. Thank you very much. Below is the tex of the figure. I also the image illustrating the wanted target.


% Define the flowchart
\tikzstyle{startstop} = [draw, rounded rectangle, text centered, draw=black]
\tikzstyle{io} = [trapezium, trapezium left angle=70, trapezium right angle=110, text centered, draw=black]
\tikzstyle{process} = [rectangle,inner sep=-0.1ex, minimum height=1cm, text centered, text width=4cm, draw=black]
\tikzstyle{decision} = [diamond, aspect=2, inner sep=-1ex,  text centered, text width=4cm,  draw=black]
\tikzstyle{arrow} = [thick,->,>=stealth, rounded corners]
\begin{tikzpicture}[node distance=1.4cm]
\node (start) [startstop] {Start};
\node (in1) [io, below = 0.5 of start, align= center] {$V$: an input sample vector \\ $\alpha$: a user-specified number};
\node (pro1) [process, below of=in1] {Do something};
\node (pro2) [process, below of=pro1] {Do something};
\node (pro3) [process, right of=pro2, xshift=4cm] {Do something};
\node (dec1) [decision, above of=pro3, yshift=0.4cm] {Check condition?};
\node (out1) [io, above of = dec1, yshift=0.4cm] {Output something};
\node (stop) [startstop, above = 0.5 of out1] {Stop};
\node (fit1) [dashed, rounded corners, fill=none, fit=(in1) (pro2), draw] {};
\node (fit2) [dashed, rounded corners, fill=none, fit=(pro3) (out1), draw] {};
\node[rotate=90, anchor=south] at (fit1.west) {The first step};
\node[rotate=90, anchor=south] at (fit2.west) {The second step};

\draw [arrow] (start) -- (in1);
\draw [arrow] (in1) -- (pro1);
\draw [arrow] (pro1) -- (pro2);
\draw [arrow] (pro2) -- (pro3);
\draw [arrow] (pro3) -- (dec1);
\draw (dec1.east) node[above right, xshift=0.4cm] {False}; \node[above left] at (dec1.north) {True};
\draw [arrow] (dec1.east) -- +(1,0) |- (pro3);
\draw [arrow] (dec1) -- (out1);
\draw [arrow] (out1) -- (stop);


enter image description here

Best Answer

enter image description here

Node with fit=<node name> actually consider width of the text in node with shapes trapezium and diamond and not their shapes extremes. This means, that we need to consider <node name>.bottom left corner and <node name>.top right corner at trapezium and <node name>.west and <node name>.east at diamond shapes.

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

   node distance = 8mm and 12mm,
     start chain = A going below,
     start chain = B going above,
     base/.style = {draw, align=center, 
                    inner sep=2mm, on chain=A, join=by arr},
startstop/.style = {base, rounded rectangle},
       io/.style = {base, text width=42mm, trapezium, trapezium stretches body,
                    trapezium left angle=75, trapezium right angle=105},
  process/.style = {base, text width=44mm, minimum height=1cm},
 decision/.style = {base, text width=40mm, diamond, aspect=2, inner xsep=-4mm},
      arr/.style = {-stealth}
\node   [startstop] {Start};                        % A-1
\node   [io] {$V$: an input sample vector \\ 
              $\alpha$: a user-specified number};
\node   [process] {Do something};
\node   [process] {Do something};                   % A-4
    \node (f1) [draw, rounded corners, dashed, 
                fit=(A-2.bottom left corner) (A-2.top right corner) (A-4),
                label={[rotate=90, anchor=south]left:The first step}] {};
    \begin{scope}[base/.append style={on chain=B}]  % B-1
\node   [process, right=of A-4] {Do something};
\node   [decision]      {Check condition?};
\node   [io]            {Output something};
\node   [startstop]     {Stop};                     % B-4
\draw[arr]  (A-4) -- (B-1);
\draw[arr] (B-2.east) node (false) [above right] {False} -- + (1,0) |- (B-1);
\node[above left] at (B-2.north) {True};
    \node (f2) [draw, rounded corners, dashed, 
                fit=(B-1) (B-3.bottom left corner) (B-3.top right corner) (false),
                label={[rotate=90,anchor=south]left:The second step}] {};

Note: node names are determined by chain name: A-i for nodes in the left branch of the flowchart and B-i for nodes in the right branch.