0

I've a flowchart created in the following manner

\tikzstyle{steps} = [rectangle, rounded corners, minimum width=3cm, minimum height=1cm, text centered, text width=3cm, draw=black, fill=gray!50]
    \tikzstyle{process} = [rectangle, minimum width=3cm, minimum height=2cm, text centered, text width=4cm, draw=black, fill=white]
    \definecolor{arrowblue}{RGB}{98,145,224}



\newcommand\ImageNode[3][]{
    \node[draw=arrowblue!80!black,linewidth=1pt,#1](#2){\includegraphics[width=1.5cm,height=1.5cm]{#3}};
}

\begin{tikzpicture}[node distance=2cm]
\node (step1) [steps] {Step 1};
\node (step2) [steps, right of=step1, xshift=3cm]{Step 2};
\node (step3) [steps, right of=step2, xshift=3cm]{Step 3};
\node (process1) [process, below of=step1] {text text};
\node (process2) [process, right of=process1, xshift=3cm] {text text
    text text text text text text text text text text text text text text text text};
\node (process3) [process, right of=process2, xshift=3cm] {text text text};
\end{tikzpicture}

enter image description here

I'd like to add background color in gradients of red for step1 , step 2 and step 3. I am not sure how to do this because step1, step2, and step3 aren't specified as columns in the current setting.

Any suggestions on how to do this will b really helpful.

EDIT: I am looking for a way to create columns and fill the background color of nodes in a given column. I don't want to color the nodes. I want the boxes in step1 to be in column1, step2-column2 and step3-column3

EDIT2: I find additional boxes around the flowchart, I am not sure why this occurs. Any suggestions on how to remove these lines will be really helpful.

enter image description here

EDIT 3: I have added decision/.style = {diamond, minimum height=1cm , draw=black, fill=white, inner sep=2mm}, to the solution provided below

enter image description here

The column heights are uneven. I'd couldn't find an option to set maximum height to styles. Suggestions on how to set uniform column heights will be really helpful.

1
  • There are no multicols in the code example.
    – Cicada
    May 27, 2020 at 11:26

2 Answers 2

1

Like this?

enter image description here

\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{backgrounds,
                fit,
                positioning}

\begin{document} 
    \begin{tikzpicture}[
 node distance = 4mm and 4mm,
   base/.style = {rectangle, draw, align=center}, 
  steps/.style = {base, rounded corners, fill=gray!50, 
                  minimum height=1cm, text width=3cm},
process/.style = {base,
                  minimum height=2cm, text width=4cm, fill=white}
                  ]
\node (process1) [process]                      {text text};
\node (process2) [process, right=of process1]   {text text
    text text text text text text text text text text text text text text text text};
\node (process3) [process, right=of process2]   {text text text};
\node (step1) [steps, above=of process1]                   {Step 1};
\node (step2) [steps, above=of process2]   {Step 2};
\node (step3) [steps, above=of process3]   {Step 3};
%
\scoped[on background layer]
{
\node[fit=(step1) (process1), fill=red!20] {};
\node[fit=(step2) (process2), fill=red!40] {};
\node[fit=(step3) (process3), fill=red!60] {};
}
    \end{tikzpicture}
\end{document}

Adendum: If you use article document class with 12 pt font size, you need to make the following changes in the above proposed solution: replace \documentclass[tikz, margin=3mm]{standalone} with

\documentclass[12pt]{article}
\usepackage{tikz}

and reduce width of nodes (since otherwise protrude out of the right text border).

At this changes you may slightly improve image code as is done in the following MWE:

\documentclass[12pt]{article}   % changed
\usepackage{tikz}               % added
\usetikzlibrary{backgrounds,
                fit,
                positioning}

\begin{document} 
\begin{figure}[ht]
\centering
    \begin{tikzpicture}[
  node distance = 4mm and 5mm,
    base/.style = {rectangle, draw, inner sep=2mm, align=center}, 
   steps/.style = {base, rounded corners, fill=gray!50, 
                   minimum height=1cm, text width=24mm},    % changed
 process/.style = {base,
                   minimum height=3cm, text width=34mm,     % changed 
                   fill=white},
FIT/.style args = {#1/#2}{base, draw=none, fit=#1, fill=#2} % added
                  ]
\node (process1) [process]                      {text text};
\node (process2) [process, right=of process1]   {text text
    text text text text text text text text text text text text text text text text};
\node (process3) [process, right=of process2]   {text text text};
\node (step1) [steps, above=of process1]                   {Step 1};
\node (step2) [steps, above=of process2]   {Step 2};
\node (step3) [steps, above=of process3]   {Step 3};
%
\scoped[on background layer]
{
\node[FIT=(step1) (process1)/red!20] {};
\node[FIT=(step2) (process2)/red!40] {};
\node[FIT=(step3) (process3)/red!60] {};
}
    \end{tikzpicture}
\end{figure}
\end{document}

Result is now (to my opinion) a bit nicer :-) :

enter image description here

9
  • Thanks a lot. This is exactly what I was looking for. Could you please let me know how to do the same in \documentclass[12pt]{article}? I want to include the above format in a manuscript
    – Natasha
    May 28, 2020 at 10:49
  • 1
    Dear Natasha, since you not provide any information about your document, I just use my standard container for drawing tikzpicture. Please, edit your question and extend your code fragment to complete small, compilable document. With this other people can help you too. See addendum to my answer
    – Zarko
    May 28, 2020 at 11:13
  • Sorry, I about that. This updated answer with article class works fine. But there was an issue. Could you please have a look at my edit in the original post?
    – Natasha
    May 28, 2020 at 14:59
  • 1
    @Natasha, if you would read received code, than you if you were to review the code of the proposed solution, you would see that it contained a part that shows the shape of the paper and must be deleted in the actual document. I just erase it, so the borders of the text, the page header and the margin-par edge are no longer visible.
    – Zarko
    May 28, 2020 at 15:22
  • Thanks a lot, Could you please explain FIT/.style args = {#1/#2}{base, draw=none, fit=#1, fill=#2} % added this lin of the code? For instance, how should the above line be modified while new styles have to be added decision/ .style = {diamond, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=white},
    – Natasha
    May 28, 2020 at 15:27
1

Background colour is done by the fill= option. Take it out of the process style, and put it in each node separately.

tikz

MWE

\documentclass{article}
\usepackage{tikz}

\tikzstyle{steps} = [rectangle, rounded corners, minimum width=3cm, minimum height=1cm, text centered, text width=3cm, draw=black, fill=gray!50]
    \tikzstyle{process} = [rectangle, minimum width=3cm, minimum height=2cm, text centered, text width=4cm, draw=black]
    \definecolor{arrowblue}{RGB}{98,145,224}



\newcommand\ImageNode[3][]{
    \node[draw=arrowblue!80!black,linewidth=1pt,#1](#2){\includegraphics[width=1.5cm,height=1.5cm]{#3}};
}

\begin{document}
\begin{tikzpicture}[node distance=2cm]
\node (step1) [steps] {Step 1};
\node (step2) [steps, right of=step1, xshift=3cm]{Step 2};
\node (step3) [steps, right of=step2, xshift=3cm]{Step 3};
\node (process1) [fill=red!10, process, below of=step1] {text text};
\node (process2) [fill=red!30, process, right of=process1, xshift=3cm] {text text
    text text text text text text text text text text text text text text text text};
\node (process3) [fill=red!90, process, right of=process2, xshift=3cm] {text text text};
\end{tikzpicture}
\end{document}
1
  • Sorry if I wasn't clear. But I am looking for a way to create columns and fill the background color of nodes in a given column. I don't want to color the nodes. I want the boxes in step1 to be in column1, step2-column2 and step3-column3
    – Natasha
    May 27, 2020 at 12:03

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.