3

I have drawn three rows of multiple containers with Tikz, with the different rows united by some arrows. Is there any way to automatically make the arrows between the rows curved and 'better-looking'?

My minimal example so far:

\documentclass[preprint,12pt]{elsarticle}

\usepackage[utf8]{inputenc}
\usepackage{color}
\usepackage[british]{babel}
\usepackage{caption}
\usepackage{gensymb}
\usepackage{pdflscape}
\usepackage{comment}
\usepackage{graphicx}
\usepackage{subfig}
\usepackage{amsmath,amsfonts,amstext,amssymb,amsbsy,amsopn,eucal,dsfont,mathtools}
\mathtoolsset{mathic}
\usepackage{multirow}
\usepackage{graphicx,adjustbox}
\usepackage{tikz}
\usetikzlibrary{fit, arrows, calc, positioning}
\usetikzlibrary{shadows,arrows.meta,positioning,backgrounds,fit,chains,scopes}
\begin{document}

\tikzstyle{Rectangle} = [
    rectangle,
    draw,
    fill=#1!20,
    node distance=1.5 cm,
    text width=7 em,
    text centered,
    rounded corners,
    minimum height=4 em,
    minimum width=3 cm,
    thick
]

\tikzstyle{blueDiamond} = [
    diamond,
    draw,
    fill=blue!20,
    node distance=1.5 cm,
    text width=7 em,
    text badly centered,
    inner sep=0pt,
    thick
]

\tikzstyle{blueEllipse} = [
    ellipse,
    draw,
    fill=blue!20,
    node distance=1.5 cm,
    text width=7 em,
    thick
]

\tikzstyle{container} = [
    rectangle,
    draw,
    inner sep=0.2 cm,
    dashed
]

\tikzstyle{empty} = [
]

\tikzstyle{line} = [
    draw,
    -latex',
    thick
]

\begin{figure}
\centering
\begin{adjustbox}{max width=\textwidth}
\begin{tikzpicture}[auto]

    \node [empty](origin){};
    \node [Rectangle=blue, below=of origin] (preproc_3) {C};
    \node [Rectangle=blue, left=of preproc_3] (preproc_2) {B};
    \node [Rectangle=blue, left=of preproc_2] (preproc_1) {A};
    \node [Rectangle=blue,  right=of preproc_3] (preproc_4) {D};
    \node [Rectangle=blue,  right=of preproc_4] (preproc_5) {E};    

    \node [Rectangle=green, below=of preproc_2](featext_1){AA};
    \node [Rectangle=green, right=of featext_1] (featext_2) {EEA};
    \node [Rectangle=green, right=of featext_2](featext_3){EEB};

    \node [Rectangle=yellow, below left = of featext_2](class_1){F};
    \node [Rectangle=yellow, below right=of featext_2](class_2){G};

    \node [container, fit=(preproc_1)(preproc_5), label=right:Data preprocessing](container1){};
    \node [container, fit=(featext_1)(featext_3), label=right:Feature extraction](container2){};
    \node [container, fit=(class_1)(class_2), label=right:Classification](container3){};

    \path [line] (preproc_1) -- (preproc_2) node[midway, left]{};
    \path [line] (preproc_2) -- (preproc_3) node[midway, left]{};
    \path [line] (preproc_3) -- (preproc_4) node[midway, left]{};
    \path [line] (preproc_4) -- (preproc_5) node[midway, left]{};

    \path [line] (preproc_1) -- (featext_1) node[midway, left]{};
    \path [line] (preproc_5) -- (featext_2) node[midway, left]{};
    \path [line] (preproc_5) -- (featext_3) node[midway, left]{};

    \path [line] (featext_1) -- (class_1) node[midway, left]{};
    \path [line] (featext_1) -- (class_2) node[midway, left]{};
    \path [line] (featext_2) -- (class_1) node[midway, left]{};
    \path [line] (featext_2) -- (class_2) node[midway, left]{};
    \path [line] (featext_3) -- (class_1) node[midway, left]{};
    \path [line] (featext_3) -- (class_2) node[midway, left]{};

\end{tikzpicture}
\end{adjustbox}
\caption{My (non-centered...) trial}
  \label{fig:Data pipeline}
\end{figure}

\end{document}
  • beginning with preamble of your document is missing ... – Zarko Mar 27 '18 at 14:35
  • @Zarko I included the rest now – AlexGuevara Mar 27 '18 at 14:40
  • 1
    my test show that your pictures looks nice. arrows can not be automatically bent. you should determined which one and how. your code use deprecated syntax (\tikzstyale). also try to avoud to use adjustbox, rather redesign image or scale it in tikz level. – Zarko Mar 27 '18 at 14:43
3

after some changes of your code, which include

  • removing adjustbox
  • redefine style Rectangle
  • use tikz library chains
  • move node distance out of node style definition
  • added definition for label's style
  • redeign the way of drawing of arrows (partly by join, partčy by edge)

i obtain:

enter image description here

(red lines indicate page layout)

\documentclass[preprint,12pt]{elsarticle}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
                chains,
                fit,
                positioning,
                shapes.geometric}
\makeatletter
\tikzset{suppress join/.code={\def\tikz@after@path{}}}
\makeatother
\tikzset{
Rectangle/.style = {
    rectangle,
    draw, thick,
    rounded corners,
    fill=#1!20,
    minimum height=12 mm,
    minimum  width=16 mm,
    text width =\pgfkeysvalueof{/pgf/minimum width}-2*\pgfkeysvalueof{/pgf/inner xsep},
    align=center},
container/.style = {
    rectangle,
    draw,
    inner sep=2 mm,
    dashed,
    node contents={}},
line/.style = {
    draw, semithick,
    -Stealth,
    thick}
}

%------------- show page layout. don't use this in real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%

\begin{document}
    \begin{figure}
\centering
    \begin{tikzpicture}[
node distance = 12mm and 6mm,
  start chain = going right,
Rectangle/.append style = {on chain, join=by line},
Rectangle/.default = blue,
every label/.append style = {align=left}
                        ]
% nodes in the first row
\node [Rectangle] (preproc_1) {A};
\node [Rectangle] (preproc_2) {B};
\node [Rectangle] (preproc_3) {C};
\node [Rectangle] (preproc_4) {D};
\node [Rectangle] (preproc_5) {E};
% nodes in the second row
    \begin{scope}[Rectangle/.append style = {suppress join}]
\node [Rectangle=green,
       below=of preproc_2]  (featext_1) {AA};
\node [Rectangle=green]     (featext_2) {EEA};
\node [Rectangle=green]     (featext_3) {EEB};
% nodes in the third row
\node [Rectangle=yellow, below  left=of featext_2]  (class_1) {F};
\node [Rectangle=yellow, below right=of featext_2]  (class_2) {G};
    \end{scope}
% containers
\node [container,
       fit=(preproc_1) (preproc_5),
       label=right: Data\\ preprocessing];
\node [container,
       fit=(featext_1) (featext_3),
       label=right: Feature\\ extraction];
\node [container,
       fit=(class_1) (class_2),
       label=right: Classification];
% arrows
\draw [line]    (preproc_1) edge (featext_1)
                (preproc_5) edge (featext_2)
                (preproc_5) edge (featext_3)

                (featext_1) edge (class_1)
                (featext_1) edge (class_2)
                (featext_2) edge (class_1)
                (featext_2) edge (class_2)
                (featext_3) edge (class_1)
                (featext_3)  to  (class_2);

\end{tikzpicture}
%\end{adjustbox}
\caption{My (non-centered ...) trial}
  \label{fig:Data pipeline}
    \end{figure}
\end{document}

please explain how would you like to have bent arrows.

addendum:

enter image description here

if you liked above image ... than make the following changes to drawing arrows:

\draw [line]    (featext_1) edge (class_1)
                (featext_1.south) edge [bend right] (class_2.west)
                (featext_2) edge (class_1.east)
                (featext_2) edge (class_2.west)
                (featext_3.south) edge [bend  left] (class_1.east)
                (featext_3)  to  (class_2);
\draw [line]    
    (preproc_1.south) .. controls +(1,-1) and +(-1,1) .. (featext_1.north);
\draw [line]
    (preproc_5.south) .. controls +(-1,-1) and +(1,1) .. (featext_2.north);
\draw [line]
    (preproc_5.south) .. controls +(-1,-1) and +(0.8,0.8) .. (featext_3.north);
  • What I was looking for was something like the spline option in GraphViz for example. – AlexGuevara Mar 27 '18 at 16:30
  • sorry, but this is not clarify me, what arraws you like. can you draw by hand over my image, what you like to have. or show image of arrows which you like to have – Zarko Mar 27 '18 at 16:33
  • thank you for your help. What I imagine is something like this – AlexGuevara Mar 27 '18 at 16:44
  • 1
    @AlexGuevara, see addendum. – Zarko Mar 27 '18 at 17:18

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.