5

How to make a horizontal flow diagram in latex like:

enter image description here

If posible i would like some colors in it.

Thank you

7

With a small hack into the package code, it is possible to get arrows with the right direction:

\documentclass[border=10pt]{standalone}
\usepackage{smartdiagram}

\makeatletter
\NewDocumentCommand{\smartdiagramx}{r[] m}{%
    \StrCut{#1}{:}\diagramtype\option
    \IfStrEq{\diagramtype}{flow diagram}{% true-flow diagram
        \begin{tikzpicture}[every node/.style={align=center,let hypenation}]

        \foreach \smitem [count=\xi] in {#2}  {\global\let\maxsmitem\xi}

        \foreach \smitem [count=\xi] in {#2}{%
            \edef\col{\@nameuse{color@\xi}}
            \IfStrEq{\option}{horizontal}{% true-horizontal-flow diagram
                \path let \n1 = {int(0-\xi)}, \n2={0+\xi*\sm@core@modulexsep} in
                node[module,drop shadow] (module\xi) at +(\n2,0) {\smitem};
            }{% false-horizontal-flow diagram
            \path let \n1 = {int(0-\xi)}, \n2={0-\xi*\sm@core@moduleysep} in
            node[module,drop shadow] (module\xi) at +(0,\n2) {\smitem};
        }
    }%

    \foreach \smitem [count=\xi] in {#2}{%
        \pgfmathtruncatemacro{\xj}{mod(\xi, \maxsmitem) + 1)}
        \edef\col{\@nameuse{color@\xj}}
        \ifnum\xi<\maxsmitem
        \begin{pgfonlayer}{smart diagram arrow back}
        \draw[diagram arrow type] (module\xi) -- (module\xj);
        \end{pgfonlayer}
        \fi
        % last arrow - not display it in background - check if disabled
        \ifbackarrowdisabled
        \relax
        \else
        \ifnum\xi=\maxsmitem
        \IfStrEq{\option}{horizontal}{% true-horizontal-flow diagram
            \tikzset{square arrow/.style={
                    to path={-- ++(0,-\sm@core@backarrowdistance) -| (\tikztotarget)}
                }
            }
            \begin{pgfonlayer}{smart diagram arrow back}
            \draw[diagram arrow type, square arrow]
            (module\xi.south) to (module\xj.south); % <== 
            \end{pgfonlayer}
        }{% false-horizontal-flow diagram
        \tikzset{square arrow/.style={
                to path={-- ++(\sm@core@backarrowdistance,0) |- (\tikztotarget)}
            }
        }
        \draw[diagram arrow type,square arrow]
        (module\xj.east) to (module\xi);
    }
    \fi
    \fi
}%
\end{tikzpicture}
}{}% end-flow diagram
}   
\makeatother

\begin{document}
 \smartdiagramset{set color list={darkgray!90, darkgray!70,gray!70,gray!50,gray!25},
   arrow style=-latex,
   uniform arrow color=true,
   arrow color=gray,
   module x sep=4.5,
   back arrow distance=0.75,
   arrow line width=2.5pt,
   text width =3cm,
 }
 \smartdiagramx[flow diagram:horizontal]{Hydraulikstation,Kontraventil,
    Cointainer,Oliefilter,Proportional ventil}
\end{document}

The result:

enter image description here

  • 2
    It will be nice if the is added as an option in the package: to have the arrow from top (default) and at the bottom (optional). – user11232 Oct 6 '15 at 13:35
  • @HarishKumar: I was indeed thinking to something like this ;) – Claudio Fiandrino Oct 6 '15 at 13:37
  • So can we expect it in the next update? :) – user11232 Oct 6 '15 at 13:40
  • 2
    @HarishKumar: Definitely! Hope to have some time and make it soon :) – Claudio Fiandrino Oct 6 '15 at 13:41
  • 2
    @CroCo smartdiagram is simpler to use, but TikZ is obviously more flexible because smartdiagram is providing you with ready-made TikZ solutions and any recipe book limits your degrees of freedom by design. – cfr Oct 7 '15 at 1:21
7

Something like this:

enter image description here

MWE:

\documentclass[border=3mm,tikz,preview]{standalone}
\usetikzlibrary{arrows.meta,chains}

    \begin{document}
    \begin{tikzpicture}[
    > = {Latex[]},
    start chain = going right,
    node distance=7mm,
    block/.style={shape=rectangle, draw,
                  inner sep=1mm, align=center,
                  minimum height=7mm, 
                  join=by ->, on chain}]
%placing the blocks
\node[block] (n1) {Hydraulikstation};
\node[block] (n2) {Kontraventil};
\node[block] (n3) {Cointainer};
\node[block] (n4) {Oliefilter};
\node[block] (n5) {Proportional ventil};
%
\draw[->] (n5.south) --  + (0,-7mm) -| (n1.south);
    \end{tikzpicture}%
\end{document}

Put any colour as you like:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,chains}

    \begin{document}
    \begin{tikzpicture}[
    > = {Latex[]},
    auto,
    start chain = going right,
    node distance=5mm,
    block/.style={shape=rectangle, draw,top color=olive,bottom color=magenta,
                  inner sep=1mm, align=center,
                  minimum height=3em, 
                  join=by ->, on chain}]

   \node[block] (n1) {Hydraulikstation};
   \node[block] (n2) {Kontraventil};
   \node[block] (n3) {Container};
   \node[block] (n4) {Oliefilter};
   \node[block] (n5) {Proportinalventil};
   \draw[->] (n5.south) -- ++(0,-4mm) -| (n1.south);
    \end{tikzpicture}%
    \end{document}

enter image description here

Edit: After reading of other (very nice and interesting answers) I recognize, that the coloring is one of wishes in questions ... :-). How to do this, I explained in other answers as well showed in Harish Kumar (thank youu!) hijack of this one. So I will add an example with shadows. In it I also slightly change TikZ (pre)settings: now the style of joins are defined separately, what enable more freedom in their design.

enter image description here

    \begin{tikzpicture}[
                > = {Triangle[]},
      start chain = going right,
    node distance = 7mm,
every join/.style = {->, very thick, gray},
    block/.style={shape=rectangle, draw,
                  inner sep=1mm, align=center,
                  minimum height=7mm, 
                  fill=white, drop shadow,
                  join, on chain}]
%placing the blocks
\node[block] (n1) {Hydraulikstation};
\node[block] (n2) {Kontraventil};
\node[block] (n3) {Cointainer};
\node[block] (n4) {Oliefilter};
\node[block] (n5) {Proportional ventil};
%
\draw[every join] (n5.south) --  + (0,-7mm) -| (n1.south);
    \end{tikzpicture}%
\end{document}
  • Zarko: I hijacked your answer. Hope you won't mind. :) – user11232 Oct 6 '15 at 11:11
  • @HarishKumar, now is very colorful :-), Thank you! – Zarko Oct 6 '15 at 11:17
7

For simple diagrams, smartdiagram allows you to just list the elements and type of diagram you want. For example:

\documentclass{article}
\usepackage{smartdiagram}
\usesmartdiagramlibrary{additions}
\begin{document}
\smartdiagramset{back arrow disabled=true}
\smartdiagramadd[flow diagram:horizontal]{%
  Thing 1, Thing 2, Thing 3, Thing 4, Thing 5
}{%
  below of module1/,below of module2/,below of module3/,below of module4/,below of module5/
}
\smartdiagramconnect{<-}{module1/additional-module1.center}
\smartdiagramconnect{-,line cap=round}{additional-module1.center/additional-module5.center}
\smartdiagramconnect{-}{module5/additional-module5.center}
\end{document}

smarter flow diagram, possibly

The colours, arrows etc. can be customised using the package's keys.

If you can have the arrow between the last and first thing above the diagram, it is simpler:

\documentclass{article}
\usepackage{smartdiagram}
\begin{document}
\smartdiagram[flow diagram:horizontal]{%
  Thing 1, Thing 2, Thing 3, Thing 4, Thing 5
}
\end{document}

simpler case

Again, colours and arrows can be customised to your liking.

EDIT Corrected the gappy arrow in the first version thanks to Harish Kumar's suggestion.

  • 1
    line cap=round in \smartdiagramconnect{-,line cap=round}{additional-module1.center/additional-module5.center} will make that connection well connected. – user11232 Oct 7 '15 at 0:20
  • @HarishKumar Thanks! That is much improved, I think, even if my solution is still rather hackish ;). – cfr Oct 7 '15 at 1:18
  • Anything that produces the required out put is not hacky IMO :) And your idea is good. Actually, I too had a solution similar to yours but I was travelling from college to home. I logged in only to find your code ;-) Nice. – user11232 Oct 7 '15 at 4:20

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.