-1

My code is complete, I just want the image to be more pretty by adding colors in boxes and arrows. enter image description here

here's the code:

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

    \begin{document}
    \begin{figure}[h]
    \centering
    % Define block styles
\tikzset{block/.style={rectangle, draw, 
text width=23mm, text centered, rounded corners, minimum height=3.5em},
line/.style={draw, -latex'}}
\begin{tikzpicture}[node distance = 1cm, auto]
% Place nodes
\node [block] (Susceptible S) {Susceptible S};
\node [block, right=of Susceptible S] (Exposed E) {Exposed E};
 \node[block, right=of  Exposed E] (Infectious I){Infectious I};
 \node[block, right=of  Infectious I] (Recovered R){Recovered R};
  % Draw edges
   \path [line] (Susceptible S) -- (Exposed E);
\path[line] (Exposed E) -- (Infectious I);
\path[line] (Infectious I) -- (Recovered R);
\end{tikzpicture}
\caption{Flow diagram of the SEIR model.}
\label{fig:seir-flow}
 \end{figure} 
 \end{document} 
2
  • Did you read about the fill option in the pgfmanual? It’s about time, as you asked the same question earlier today …
    – MS-SPO
    Commented Jun 4 at 20:05
  • 1
    Hi and welcome. Write simply \tikzset{block/.style={rectangle, draw, text width=23mm, text centered,fill=green!50,draw=blue, rounded corners, minimum height=3.5em},line/.style={draw, -latex',blue}}
    – AndréC
    Commented Jun 4 at 20:15

2 Answers 2

3

It is often convenient to add an argument to a style when you want to change one particular aspect. For example, you can add fill=#1 to your block style. Then you can use the option block=<color> in your code. You can also set a default as in the code below. You can do the same for your line style.

A few suggestions: The Latex arrow tip from arrows.meta is a bit more pronounced and can be modified in many ways if you wish. I also simplified the names of the nodes which I think is easier to read but that's just personal opinion.

enter image description here

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows.meta, positioning}

\tikzset{
    block/.style={rectangle, draw, text width=23mm, text centered, 
        rounded corners, minimum height=3.5em, fill=#1},
    block/.default=none,
    line/.style={draw=#1, -Latex},
    line/.default=black
}

\begin{document}

\begin{figure}[h]
\centering
\begin{tikzpicture}[node distance = 1cm, auto]
% Place nodes
  \node[block=blue!20] (S) {Susceptible S};
  \node[block=yellow!30, right=of S] (E) {Exposed E};
  \node[block=red!20, right=of E] (I){Infectious I};
  \node[block=green!20, right=of I] (R){Recovered R};
% Draw edges
  \path[line=blue] (S) -- (E);
  \path[line] (E) -- (I);
  \path[line=red] (I) -- (R);
\end{tikzpicture}
\caption{Flow diagram of the SEIR model.}
\label{fig:seir-flow}
\end{figure} 

\end{document}
3

Added the colors in the boxes.

\documentclass[12pt]{article}
\usepackage{geometry}%<----To have centered the blocks
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows, positioning}

\begin{document}
\begin{figure}[h]
\centering
\tikzset{
    block/.style={rectangle, draw, text width=23mm, text centered, rounded corners, minimum height=3.5em},
    line/.style={draw, -latex', thick} %<--------Define block styles
}
%%%%%%%%%%%%% Define the blocks %%%%%%%%%%%%%%%%
\begin{tikzpicture}[node distance = 1.5cm, auto]
\node [block, fill=blue!30] (SusceptibleS) {Susceptible S};
\node [block, fill=orange!30, right=of SusceptibleS] (ExposedE) {Exposed E};
\node [block, fill=red!30, right=of ExposedE] (InfectiousI) {Infectious I};
\node [block, fill=green!30, right=of InfectiousI] (RecoveredR) {Recovered R};
%%%%%%%%%%%%%%% Draw edges %%%%%%%%%%%%%%%%%%
\path [line] (SusceptibleS) -- (ExposedE);
\path [line] (ExposedE) -- (InfectiousI);
\path [line] (InfectiousI) -- (RecoveredR);
\end{tikzpicture}
\caption{Flow diagram of the SEIR model.}
\label{fig:seir-flow}
\end{figure}
\end{document}

enter image description here

If you want the color in the arrows put, for example, \path [line, red], \path [line, orange], ecc.

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .