0

I'm trying to create a flowchart adapting the code from Header in tikz container for flowchart but the blocks are not centralized (I can't upload the image).

!(https://ibb.co/Dt8Q3L3)

The code I used:

\documentclass[12pt]{article}
\usepackage{tikz}
\usepackage[active,tightpage]{preview}
\usetikzlibrary{shapes,arrows.meta,calc,fit,backgrounds,shapes.multipart,positioning}
\tikzset{box/.style={draw, rectangle, rounded corners, thick, node 
distance=7em, 
text width=6em, text centered, minimum height=3.5em}}
\tikzset{every node/.style={font=\scriptsize}}

\PreviewEnvironment{tikzpicture}

\setlength\PreviewBorder{4pt}%

\begin{document}

\tikzset{block/.style={rectangle split, draw, rectangle split parts=2, text width=14em, text centered, rounded corners, minimum height=4em}, grnblock/.style={rectangle, draw, fill=green!20, text width=10em, text centered, rounded corners, minimum height=4em}, whtblock/.style={rectangle, draw, fill=white!20, text width=10em, text centered, minimum height=4em},
line/.style={draw, -{Latex[length=2mm,width=1mm]}}, cloud/.style={draw, ellipse,fill=white!20, node distance=3cm, minimum height=4em},
container/.style={draw, rectangle,dashed,inner sep=0.28cm, rounded corners,fill=yellow!20,minimum height=4cm}}

\begin{tikzpicture}[node distance = 1.25cm, auto]

\node [whtblock,font=\fontsize{10}{0}\selectfont] (MicFEM) {Finite element mesh};

\node [whtblock, below=of MicFEM, node distance=2.5cm,font=\fontsize{10}{0}\selectfont] (ROM) {Generate Reduced Order};

\node [grnblock, left=of MicFEM,,node distance=7cm,font=\fontsize{10}{0}\selectfont] (Morph) {Text text text text text};

\node [block, right=of MicFEM,node distance=7cm,rectangle split part fill={orange!20,blue!5},font=\fontsize{10}{0}\selectfont] (ConstElasProp) {Constituent \nodepart[text width=7.5cm]{two} - Text text text text text;\[0.3em]- Text text text text text;\[0.3em]- Text text text text text;\[0.3em]- Text text text text text.};

\node [whtblock, below=of ROM, node distance=2.5cm,font=\fontsize{9}{0}\selectfont] (CfTns) {Compute coefficient};

\node [whtblock, below=of CfTns, node distance=3.5cm,font=\fontsize{10}{0}\selectfont] (STAGE1) {First stage};

\node [whtblock, right=of STAGE1,font=\fontsize{10}{0}\selectfont] (STAGE2) {Second stage};

\node [whtblock, right=of STAGE2,font=\fontsize{10}{0}\selectfont] (STAGE3) {Third stage};

\node [whtblock, right=of STAGE3,font=\fontsize{10}{0}\selectfont] (STAGE4) {Fourth stage};

\node [whtblock, below=of STAGE4,font=\fontsize{10}{0}\selectfont] (STAGE5) {Fifth stage};

\node [whtblock, left=of STAGE5,font=\fontsize{10}{0}\selectfont] (STAGE6) {Sixth stage};

\node [whtblock, left=of STAGE6,font=\fontsize{10}{0}\selectfont] (STAGE7) {Seventh stage};

\node [block, below=of STAGE7, node distance=3cm,rectangle split part fill={blue!20,white},font=\fontsize{10}{0}\selectfont] (Output) {\textbf{Results} \nodepart[text width=7cm]{two}Text text text text text\Text text text text text};

\begin{scope}[on background layer] \coordinate (aux1) at ([yshift=3mm]MicFEM.north); \node [container,fit=(aux1) (ROM)(CfTns)] (MICRO) {}; \node at (MICRO.north) [fill=white,draw,font=\fontsize{12}{0}\selectfont] {\textbf{Microscale}}; %----------------------------------------------------------- \coordinate (aux2) at ([yshift=3mm]STAGE1.north); \node[container, fit=(aux2) (STAGE1) (STAGE2) (STAGE3) (STAGE4) (STAGE5) (STAGE6) (STAGE7)] (MACRO) {}; \node at (MACRO.north) [fill=white,draw,font=\fontsize{12}{0}\selectfont] (MACRO-label) {\textbf{Implementation}}; \end{scope}

\path [line] (MicFEM) -- (ROM); \path [line] (ROM) -- (CfTns); \path [line] (STAGE1) -- (STAGE2); \path [line] (STAGE2) -- (STAGE3); \path [line] (STAGE3) -- (STAGE4); \path [line] (STAGE4) -- (STAGE5); \path [line] (STAGE5) -- (STAGE6); \path [line] (STAGE6) -- (STAGE7); \path [line] (MICRO) -- (MACRO-label); \path [line] (Morph) -- (MicFEM); \path [line] (ConstElasProp) -- (MicFEM); \path [line] (MACRO) -- (Output);

\end{tikzpicture} \end{document}

Besides I'd like to align the icons of the "Constitute" block on the left.

Could anyone help me with these changes?

  • 2
    remplace your images by example-image – JeT Jan 30 '24 at 13:53
  • Welcome to StackExcange. "the blocks are misaligned" When running your code, I don't see which ones. "to align the icons of the "Constitute" block on the left" I don't understand what you mean by icon. – pascal974 Jan 30 '24 at 14:33
  • You are correct, @pascal974. I meant centralized. I already corrected it in the post. If you can run the code, you will see that the "Implementation" and "Results" blocks are not centered. – jhilsamba Jan 30 '24 at 15:39

1 Answers1

1

This should help

enter image description here

Changes made

        \coordinate (aux3) at (MACRO.south);
        \node [block, below=1cm of aux3, rectangle split part fill={blue!20,white},font=\fontsize{10}{0}\selectfont] (Output) {\textbf{Results}
        \nodepart[text width=7cm]{two}Text text text text text\\Text text text text text};
        \path [line] (aux3) -- (Output);
    \path [line] (MICRO) -| (MACRO-label);  

MWE

\documentclass[12pt]{article}
\usepackage{tikz}
\usepackage[active,tightpage]{preview}
\usetikzlibrary{shapes,arrows.meta,calc,fit,backgrounds,shapes.multipart,positioning}
\tikzset{box/.style={draw, rectangle, rounded corners, thick, node 
        distance=7em, 
        text width=6em, text centered, minimum height=3.5em}}
\tikzset{every node/.style={font=\scriptsize}}

\PreviewEnvironment{tikzpicture}

\setlength\PreviewBorder{4pt}%

\begin{document}

\tikzset{block/.style={rectangle split, draw, rectangle split parts=2,
        text width=14em, text centered, rounded corners, minimum height=4em},
    grnblock/.style={rectangle, draw, fill=green!20, text width=10em, text centered, rounded corners, minimum height=4em}, 
    whtblock/.style={rectangle, draw, fill=white!20, text width=10em, text centered, minimum height=4em},    
    line/.style={draw, -{Latex[length=2mm,width=1mm]}},
    cloud/.style={draw, ellipse,fill=white!20, node distance=3cm,    minimum height=4em},  
    container/.style={draw, rectangle,dashed,inner sep=0.28cm, rounded
        corners,fill=yellow!20,minimum height=4cm}}

\begin{tikzpicture}[node distance = 1.25cm, auto]

    \node [whtblock,font=\fontsize{10}{0}\selectfont] (MicFEM) {Finite element mesh};   

    \node [whtblock, below=of MicFEM, node distance=2.5cm,font=\fontsize{10}{0}\selectfont] (ROM) {Generate Reduced Order};

    \node [grnblock, left=of MicFEM,,node distance=7cm,font=\fontsize{10}{0}\selectfont] (Morph) {Text text text text text};    

    \node [block, right=of MicFEM,node distance=7cm,rectangle split part fill={orange!20,blue!5},font=\fontsize{10}{0}\selectfont] (ConstElasProp) {Constituent
        \nodepart[text width=7.5cm]{two} - Text text text text text;\\[0.3em]- Text text text text text;\\[0.3em]- Text text text text text;\\[0.3em]- Text text text text text.};

    \node [whtblock, below=of ROM, node distance=2.5cm,font=\fontsize{9}{0}\selectfont] (CfTns) {Compute coefficient};

    \node [whtblock, below=of CfTns, node distance=3.5cm,font=\fontsize{10}{0}\selectfont] (STAGE1) {First stage};

    \node [whtblock, right=of STAGE1,font=\fontsize{10}{0}\selectfont] (STAGE2) {Second stage};

    \node [whtblock, right=of STAGE2,font=\fontsize{10}{0}\selectfont] (STAGE3) {Third stage};

    \node [whtblock, right=of STAGE3,font=\fontsize{10}{0}\selectfont] (STAGE4) {Fourth stage};

    \node [whtblock, below=of STAGE4,font=\fontsize{10}{0}\selectfont] (STAGE5) {Fifth stage};

    \node [whtblock, left=of STAGE5,font=\fontsize{10}{0}\selectfont] (STAGE6) {Sixth stage};

    \node [whtblock, left=of STAGE6,font=\fontsize{10}{0}\selectfont] (STAGE7) {Seventh stage};


    \begin{scope}[on background layer]
        \coordinate (aux1) at ([yshift=3mm]MicFEM.north);
        \node [container,fit=(aux1) (ROM)(CfTns)] (MICRO) {};
        \node at (MICRO.north) [fill=white,draw,font=\fontsize{12}{0}\selectfont] {\textbf{Microscale}};
        %-----------------------------------------------------------
        \coordinate (aux2) at ([yshift=3mm]STAGE1.north);
        \node[container, fit=(aux2) (STAGE1) (STAGE2) (STAGE3) (STAGE4) (STAGE5) (STAGE6) (STAGE7)] (MACRO) {};
        \node at (MACRO.north) [fill=white,draw,font=\fontsize{12}{0}\selectfont] 
        (MACRO-label) {\textbf{Implementation}};
        %%%%%%%%%
        \coordinate (aux3) at (MACRO.south);%..changed

    \end{scope}

    \path [line] (MicFEM) -- (ROM);
    \path [line] (ROM) -- (CfTns);
    \path [line] (STAGE1) -- (STAGE2);
    \path [line] (STAGE2) -- (STAGE3);
    \path [line] (STAGE3) -- (STAGE4);
    \path [line] (STAGE4) -- (STAGE5);
    \path [line] (STAGE5) -- (STAGE6);
    \path [line] (STAGE6) -- (STAGE7);
    \path [line] (MICRO) -| (MACRO-label);%..changed
    \path [line] (Morph) -- (MicFEM);
    \path [line] (ConstElasProp) -- (MicFEM);

%changed code here \node [block, below=1cm of aux3, rectangle split part fill={blue!20,white},font=\fontsize{10}{0}\selectfont] (Output) {\textbf{Results} \nodepart[text width=7cm]{two}Text text text text text\Text text text text text}; \path [line] (aux3) -- (Output);
\end{tikzpicture} \end{document}

EDIT1

\documentclass[12pt]{article}
\usepackage{tikz}
\usepackage[active,tightpage]{preview}
\usetikzlibrary{shapes,arrows.meta,calc,fit,backgrounds,shapes.multipart,positioning}
%\tikzset{box/.style={draw, rectangle, rounded corners, thick, node     distance=7em, 
%       text width=6em, text centered, minimum height=3.5em}}
%\tikzset{every node/.style={font=\scriptsize}}

\PreviewEnvironment{tikzpicture}

\setlength\PreviewBorder{4pt}%

\begin{document}

\tikzset{block/.style={rectangle split, draw, rectangle split parts=2,
        text width=14em, text centered, rounded corners, minimum height=4em},
    grnblock/.style={rectangle, draw, fill=green!20, text width=10em, text centered, rounded corners, minimum height=4em}, 
    whtblock/.style={rectangle, draw, fill=white!20, text width=10em, text centered, minimum height=4em},    
    line/.style={draw, -{Latex[length=2mm,width=1mm]}},
    cloud/.style={draw, ellipse,fill=white!20, node distance=3cm,    minimum height=4em},  
    container/.style={draw, rectangle,dashed,inner sep=0.28cm, rounded
        corners,fill=yellow!20,minimum height=4cm}}

\begin{tikzpicture}[node distance = 1.25cm, auto]

    \node [whtblock,] (MicFEM) {Finite element mesh};   
    \node [whtblock, below=of MicFEM,] (ROM) {Generate Reduced Order};
    \node [grnblock, left=of MicFEM,,] (Morph) {Text text text text text};    
    \node [block, right=of MicFEM,rectangle split part fill={orange!20,blue!5},] (ConstElasProp) {Constituent
    \nodepart[text width=5cm]{two} - Text text text text text;\\- Text text text text text;\\- Text text text text text;\\- Text text text text text.};
    \node [whtblock, below=of ROM, ] (CfTns) {Compute coefficient};
    \node [whtblock, below=of CfTns, ] (STAGE1) {First stage};
    \node [whtblock, right=of STAGE1,] (STAGE2) {Second stage};
    \node [whtblock, right=of STAGE2] (STAGE3) {Third stage};
    \node [whtblock, right=of STAGE3] (STAGE4) {Fourth stage};
    \node [whtblock, below=of STAGE4] (STAGE5) {Fifth stage};
    \node [whtblock, left=of STAGE5] (STAGE6) {Sixth stage};
    \node [whtblock, left=of STAGE6] (STAGE7) {Seventh stage};

    \begin{scope}[on background layer]
    \coordinate (aux1) at ([yshift=3mm]MicFEM.north);
    \node [container,fit=(aux1) (ROM)(CfTns)] (MICRO) {};
    \node at (MICRO.north) [fill=white,draw,] {\textbf{Microscale}};
        %-----------------------------------------------------------
    \coordinate (aux2) at ([yshift=3mm]STAGE1.north);
    \node[container, fit=(aux2) (STAGE1) (STAGE2) (STAGE3) (STAGE4) (STAGE5) (STAGE6) (STAGE7)] (MACRO) {};
    \node at (MACRO.north) [fill=white,draw] (MACRO-label) {\textbf{Implementation}};
        %%%%%%%%%
    \coordinate (aux3) at (MACRO.south);
    \node [block, below=1cm of aux3, rectangle split part fill={blue!20,white},font=\fontsize{10}{0}\selectfont] (Output) {\textbf{Results}
    \nodepart[text width=7cm]{two}Text text text text text\\Text text text text text};
    \end{scope}

    \path [line] (MicFEM) -- (ROM);
    \path [line] (ROM) -- (CfTns);
    \path [line] (STAGE1) -- (STAGE2);
    \path [line] (STAGE2) -- (STAGE3);
    \path [line] (STAGE3) -- (STAGE4);
    \path [line] (STAGE4) -- (STAGE5);
    \path [line] (STAGE5) -- (STAGE6);
    \path [line] (STAGE6) -- (STAGE7);
    \path [line] (MICRO) -| (MACRO-label);
    \path [line] (Morph) -- (MicFEM);
    \path [line] (ConstElasProp) -- (MicFEM);
    \path [line] (aux3) -- (Output);        
\end{tikzpicture}

\end{document}

enter image description here

js bibra
  • 21,280