[Tex/LaTex] Node relative positions and arrows with texts (Tikz)

tikz-arrowstikz-pgftikz-trees

I'm struggling to generate a Tikz Image… I've progressed so far to generate the following image:

enter image description here

However, I want to generate something like this:

enter image description here

I can't straight the arrow from B to A, nor fix the space between C and the brain image….. here follows my code:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc,trees,positioning,arrows,chains,shapes.geometric, 
    decorations.pathreplacing,decorations.pathmorphing,shapes, 
    matrix,shapes.symbols}

\begin{document}
\tikzset{
>=stealth',
  punktchain/.style={
    rectangle, 
    rounded corners, 
    draw=black, very thick,
    text width=22em, 
    minimum height=3em, 
    text centered, 
    on chain},
   small punktchain/.style={
    rectangle, 
    rounded corners, 
    draw=black, very thick,
    text width=10em, 
    minimum height=3em, 
    text centered, 
    on chain},
  line/.style={draw, thick, <-},
  element/.style={
    tape,
    top color=white,
    bottom color=blue!50!black!60!,
    minimum width=8em,
    draw=blue!40!black!90, very thick,
    text width=10em, 
    minimum height=3em, 
    text centered, 
    on chain},
  every join/.style={->, thick,shorten >=1pt},
  decoration={brace},
  tuborg/.style={decorate},
  tubnode/.style={midway, right=2pt},  
}

\begin{tikzpicture}
  [node distance=2.8cm,
  start chain=1 going below, start chain=2 going below]
  \node[punktchain] (a) {\textbf{A}}
  child[<-,thick]{node[small punktchain,anchor=east] (b) {\textbf{B}
     }
child{node[on chain, right = 1cm of b] (brain)      {\includegraphics[width=.25\textwidth]{brain.png}}
    child{node[small punktchain, join,node distance=0.8em] (c) {\textbf{C}}}}}        
     ;

     \path [->] (brain.south) to node [near start, right, text width=3em] {\textit{solves}} (c);
     \path [->] (a.south) to node [near start, right,text width=2cm] {\textit{Previous Knowledge}} (brain);
      \path [] (b.north) to node [near start, right] {\textit{advises}} (a);

  \end{tikzpicture}

\end{document}

Best Answer

I think you are trying to use altogether two many tools at the same time: positioning, chains, trees .... Doing this defeats the primary purpose of using any of them which is to simplify, structure and organise the code, making it more flexible and straightforward.

I recommend either using simple positioning, perhaps with on grid, or chains. This does not seem well-suited to being a tree.

For example, here's a way of doing it with chains. (You define 2 chains but only ever use 1 of them.) When necessary, I using positioning to place a node and then \chainin to add it to the chain and join it.

example-image-a is the brains of this operation:

sample brain

\documentclass[border=10pt,tikz,multi]{standalone}
\usetikzlibrary{positioning,arrows,chains}
\begin{document}
\tikzset{%
  >=stealth',
  punktchain/.style={
    rectangle,
    rounded corners,
    draw=black, very thick,
    text width=22em,
    minimum height=3em,
    text centered,
    font=\bfseries,
    on chain},
   small punktchain/.style={
    rectangle,
    rounded corners,
    draw=black, very thick,
    text width=10em,
    minimum height=3em,
    text centered,
    font=\bfseries,
    on chain,
  },
  line/.style={draw, thick, <-},
  element/.style={
    tape,
    top color=white,
    bottom color=blue!50!black!60!,
    minimum width=8em,
    draw=blue!40!black!90, very thick,
    text width=10em,
    minimum height=3em,
    text centered,
    on chain},
  every join/.style={->, thick, shorten >=1pt, shorten <=1pt},
}
\begin{tikzpicture}
  [node distance=2.8cm, start chain=1 going below, every label/.style={font=\itshape}, label distance=0pt]
  \node [punktchain] (a) {A};
  \node [small punktchain, on chain, anchor=east, join={with a.south -| b  by <-}, label={[anchor=south east]north east:advises}] (b) {B};
  \node [anchor=west, right=10mm of b, inner sep=0pt] (brain) {\includegraphics[width=.25\textwidth]{example-image-a}};
  \chainin (brain) [join={with a.south -| brain}];
  \node [small punktchain, join, yshift=15mm, label={[anchor=south east]north east:solves}] (c) {C};
  \draw [every join] (brain.east) [bend right=75] to (a.east);
  \node [every label, anchor=north east, align=right] at (a.south -| brain) {previous\\knowledge};
\end{tikzpicture}
\end{document}