1

I tried to draw this diagram

enter image description here

rpapa's showed me how to start by posting code to draw the 3 big boxes with circles at the top and the labels on the left and the arrows between them. That was a great help.

I've managed to modify that code to colour some of the elements. I've also created a new command which starts drawing the big box at the bottom and makes some of the connections between the circles in this box and the ones in the boxes above. However, I can't figure out how to draw the connection from the Thalamus box to the circle in the Amygdala because that arrow needs to go from the border of the big box and not from one of the circles inside it.

How can I draw a connection from the edge of the big box rather than from one of the circles?

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning,calc,fit}

\begin{figure*}[!ht]
\centering 

\newcommand{\bloc}[2]{
\begin{scope}[shift={#1}]
\begin{scope}[every node/.style={circle, draw, minimum size=2em}]  
 \node[circle, draw] [blue](#2-c1){};
 \node[below left=1em of #2-c1][blue](#2-c2){};%to draw a circle inside a box
  \node[below left=1em of #2-c2][blue](#2-c3){};
   \node[below left=1em of #2-c3][blue](#2-c4){};
 \end{scope} 
    \node[above left=1em and 0em of #2-c1][blue](#2-tt){#2};%to label the box by names Thalamus,Sensory Cortex
\node[draw,fit=(#2-c1) (#2-c2) (#2-c3) (#2-c4) (#2-tt)][red](#2){};%to draw a boxes


\end{scope}
 }







\newcommand{\blocwithSum}[2]{
\begin{scope}[shift={#1}]
\begin{scope}[every node/.style={circle, draw, minimum size=2em}]  
 \node[circle, draw] [red](#2-c1){};
 \node[below left=1em of #2-c1][red](#2-c2){};
  \node[below left=1em of #2-c2][red](#2-c3){};
   \node[below left=1em of #2-c3][red](#2-c4){};
   \node[below right=2em and 1em of #2-c1][blue](#2-sum){\large $\Sigma$};
 \end{scope} 
    \node[above left=1em and 0em of #2-c1][red](#2-tt){#2};%to label a box by name Orbitofrontal
\node[draw,fit=(#2-c1) (#2-c2) (#2-c3) (#2-c4) (#2-tt) (#2-sum)][blue](#2){};%to draw a box
\draw[->,red,thick] (#2-c1)-|(#2-sum);%to draw connection lines to sum
\draw[->,red,thick] (#2-c2)--++(2em,0) --(#2-sum);
\draw[->,red,thick] (#2-c3)--++(2em,0) --(#2-sum);
\draw[->,red,thick] (#2-c4)-|(#2-sum);
\end{scope}
 } 

 \newcommand{\blocwithz}[2]{
\begin{scope}[shift={#1}]
\begin{scope}[every node/.style={circle, draw, minimum size=2em}]  
 \node[circle, draw][cyan] (#2-c1){};
 \node[below left=1em of #2-c1][cyan](#2-c2){};%to draw circles
  \node[below left=1em of #2-c2][cyan](#2-c3){};
   \node[below left=1em of #2-c3][cyan](#2-c4){};
   \node[below left=1 em of #2-c4](#2-c5){};
   \node[below right=2em and 1em of #2-c1][red](#2-sum){\large $\Sigma$};%to draw Sum
  % \node[below right=2em and 0 em of#2-sum](#2-sums){\large$\Sigma$};
    \end{scope} 
    \node[above left=1em and 0em of #2-c1][cyan](#2-tt){#2}; %to label the  box name Amagydala
\node[draw,fit=(#2-c1) (#2-c2) (#2-c3) (#2-c4) (#2-c5) (#2-tt) (#2-sum)][cyan](#2){}; %to draw the box
\draw[->,cyan,thick] (#2-c1)-|(#2-sum);%to draw connection lines to Sum
\draw[->,cyan,thick] (#2-c2)--++(2em,0) --(#2-sum);
\draw[->,cyan,thick] (#2-c3)--++(2em,0) --(#2-sum);
\draw[->,cyan,thick] (#2-c4)-|(#2-sum);
\end{scope}
 } 






  \begin{tikzpicture}
 \bloc{(0,0)}{Thalamus} %the position of box 1

  \bloc{(4cm,0)}{Sensory Cortex} %the position of box 2

    \blocwithSum{(9cm,0)}{Orbitofrontal Cortex}  %the position of box 3

\blocwithz{(4cm,-7cm)}{Amygdala} % the position of box 4

 \foreach \ii in{1,2,3,4} {
 \node[draw][red](E\ii) at (Thalamus-c\ii-|-5,0){$S_{\ii}$};%to draw the inputs stimulus and their position
  \draw[->,thick][blue]  (E\ii)-- (Thalamus-c\ii);
  \draw[->,thick] [red](Thalamus-c\ii) -- (Sensory Cortex-c\ii);
    \draw[->,thick] [blue] (Sensory Cortex-c\ii) --  (Orbitofrontal Cortex-c\ii);  
     \draw[->,thick] [red] (Sensory Cortex-c\ii) --  (Amygdala-c\ii);  
     %\draw[->,thick] [red] (g) --  (Amygdala-c\ii);   
     }



  \end{tikzpicture}    

 \caption{ Routes of limbic system}
\label{FB2}
\end{figure*} 
\end{document}

Here's what I've got, building on rpapa's answer:

progress

  • 6
    How does this question differ from this one? – Thruston Nov 21 '15 at 12:38
  • 1
    I don't think this should have been closed. @Thruston It is not really a duplicate, because this question asks about a specific problem which the OP has encountered when trying to extend the outline solution provided in an answer to the previous question. I would like to answer this to explain how to solve that specific problem, but I can't. – cfr Nov 22 '15 at 2:55
  • I've rewritten this in a fairly major way as I think it was improperly closed because people weren't immediately clear you were asking a specific follow up. Please check that it still reflects your intended meaning. – cfr Nov 22 '15 at 3:12
  • You can use any painter to show your problem because I don't know which circle you are referring to when you say Thalamus box to the circle in the Amygdala – CroCo Nov 22 '15 at 3:16
  • @CroCo I assume the only one not currently connected to anything? I could be wrong, but it seems likely. – cfr Nov 22 '15 at 3:19
3

Possible but not perfect solution

enter image description here

\documentclass[border=10pt]{standalone}
\usepackage{tikz,bm}
\usetikzlibrary{calc,positioning,fit,arrows}


\begin{document}
\begin{tikzpicture}
    [%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        node distance=.2cm,
        whiteCircle/.style={circle,draw,very thick,
                      inner sep=0pt,minimum size=6mm},
        greyCircle/.style={circle,draw,fill=gray,very thick,
                      inner sep=0pt,minimum size=2mm},
        greyRectangle/.style={rectangle,draw,fill=gray, very thick,
                      inner sep=0pt,minimum width=2mm, minimum height=7mm},
        solidLine/.style={->,very thick,>=latex},
        dashLine/.style={->,dashed,very thick,>=latex},
        rect/.style={rectangle,draw,inner sep=0.0pt,minimum height=2mm}
    ]%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \node [whiteCircle] (A1)                    {A1};
    \node [whiteCircle] (B1) [below left=of A1] {B1};
    \node [whiteCircle] (C1) [below left=of B1] {C1};
    \node [whiteCircle] (D1) [below left=of C1] {D1};

    \node [draw, thick, inner sep=0.4cm, fit={(A1) (B1) (C1) (D1)}] (ThalamusBox) {};
    \node[below left, xshift=3mm] at (ThalamusBox.north) {\textbf{Thalamus}};
    %##########################################################
    \node[rect,node distance=5cm] (K1) [left=of A1] {$\bm{K_{p_{t-4}}}$};
    \node[rect]                   (K2) [below=of K1] {$\bm{K_{p_{t-3}}}$};
    \node[rect]                   (K3) [below=of K2] {$\bm{K_{p_{t-2}}}$};
    \node[rect]                   (K4) [below=of K3] {$\bm{K_{p_{t-1}}}$};

    %##########################################################
    \node [whiteCircle, node distance=3cm] (A2) [right=of A1]      {A2};
    \node [whiteCircle]                    (B2) [below left=of A2] {B2};
    \node [whiteCircle]                    (C2) [below left=of B2] {C2};
    \node [whiteCircle]                    (D2) [below left=of C2] {D2};

    \node [draw, thick, inner sep=0.4cm, fit={(A2) (B2) (C2) (D2)}]  (SensoryBox) {};
    \node[below, xshift=-2mm] at (SensoryBox.north) {\textbf{Sensory Cortex}};
    %##########################################################
    \node [whiteCircle, node distance=6.5cm] (A3) [right=of A2]      {A3};
    \node [whiteCircle]                      (B3) [below left=of A3] {B3};
    \node [whiteCircle]                      (C3) [below left=of B3] {C3};
    \node [whiteCircle]                      (D3) [below left=of C3] {D3};

    \node [whiteCircle,node distance=1.9cm]  (S3) [right of= C3] {$\bm{\sum}$};
    \node [draw, thick, inner sep=0.4cm, fit={(A3) (B3) (C3) (D3) (S3)}]  (OrbitoBox) {};
    \node[below, xshift=0mm] at (OrbitoBox.north) {\textbf{Orbitofrontal Cortex}};
    %##########################################################
    \node [greyCircle, node distance=3cm]     (a4) [below=of S3]   {a4};
    \node [greyRectangle,node distance=2.0cm] (b4) [left=of a4]    {b4};
    \node [greyCircle,node distance=3.2cm]    (c4) [left=of b4]    {c4};

    \node [whiteCircle,node distance=1.9cm]   (S41) [below of= a4] {$\bm{\sum}$};
    \node [greyCircle,node distance=0.9cm]    (d4)  [left=of S41]  {d4};
    \node [rect,node distance=1cm,inner sep=1.0pt,] (Kp) [right=of S41] {$\bm{\hat{K}_{p_{t}}}$};

    \node[greyRectangle] (e4)  at (c4 |- d4)   {e4};

    \node[rect] (K5) at (K4 |- c4) {$\bm{K_{p_{t}}}$};

    \node[whiteCircle,node distance=1.7cm] (A4) [below=of e4] at (barycentric cs:d4=0.1,e4=0.1)  {A4};
    \node [whiteCircle]                  (B4) [below left=of A4] {B4};
    \node [whiteCircle]                  (C4) [below left=of B4] {C4};
    \node [whiteCircle]                  (D4) [below left=of C4] {D4};
    \node [whiteCircle]                  (E4) [below left=of D4] {E4};

    \node [greyCircle,node distance=3.6cm]   (f4) [below=of d4]    {f4};
    \node [whiteCircle,node distance=1.5cm]  (S42) [left of= f4]   {$\bm{\sum}$};
    \node [whiteCircle,node distance=1.cm]   (S43) [above of= S42] {$\bm{\sum}$};

    \node [draw, thick, inner sep=0.4cm, fit={(a4)(b4)(c4)(d4)(E4)(S41)}]  (AmyBox) {};
    \node[above, xshift=2.8cm] at (AmyBox.south) {\textbf{Amygdata}};


    \draw[solidLine] (A1) -- (A2);
    \draw[solidLine] (B1) -- (B2);
    \draw[solidLine] (C1) -- (C2);
    \draw[solidLine] (D1) -- (D2);

    \draw[solidLine] (A2) -- node (w4) [above, midway,xshift=-6mm] {$\textbf{w}_{4}$} (A3);
    \draw[solidLine] (B2) --  (B3);
    \draw[solidLine] (C2) --  (C3);
    \draw[solidLine] (D2) --  (D3); 
    \node[node distance=.15cm] (w3) [below=of w4] {$\textbf{w}_{3}$};
    \node[node distance=.15cm] (w2) [below=of w3] {$\textbf{w}_{2}$};
    \node[node distance=.15cm] (w1) [below=of w2] {$\textbf{w}_{1}$};

    \draw[solidLine] (A3.east) -| (S3);
    \draw[solidLine] (B3.east) --++(1em,0) --(S3);
    \draw[solidLine] (C3.east)  --(S3);
    \draw[solidLine] (D3.east) --++(4em,0) --(S3);

    \draw[solidLine] (S3) -- node[anchor=north west,yshift=-4mm] {$\bm{E_{o}}$} (a4);
    \draw[solidLine] (a4) -- node[anchor=north east,yshift=-3mm] {\textbf{-}}(S41);
    \draw[dashLine] (a4) -- (b4);
    \draw[dashLine] (c4) -- (b4);
    \draw[dashLine] (b4) -- (w4.north east);
    \draw[dashLine] (c4) -- (e4);
    \draw[dashLine] (d4) -- (e4);
    \draw[solidLine] (d4) -- (S41);  

    \draw[solidLine] (A2) |- node[midway,above,xshift=3mm] (v4) {$\textbf{v}_{4}$} (A4);
    \draw[solidLine] (B2) |- node[midway,above,xshift=3mm] (v3) {$\textbf{v}_{3}$}(B4);
    \draw[solidLine] (C2) |- node[midway,above,xshift=3mm] (v2) {$\textbf{v}_{2}$}(C4);
    \draw[solidLine] (D2) |- node[midway,above,xshift=3mm] (v1) {$\textbf{v}_{1}$} (D4); 
    \draw[solidLine] (ThalamusBox) |- node[midway,above,xshift=25mm] (v1) {$\textbf{v}_{\psi}$} (E4);

    \draw[solidLine] (A4) -| (S43);
    \draw[solidLine] (S43) -- (S42);
    \draw[solidLine] (S43.east) -| node[anchor=south west,yshift=2mm] {$\bm{E'_{a}}$} (b4);
     \draw[solidLine] (B4.east) --++(1em,0) --(S43);
     \draw[solidLine] (C4.east) --++(9mm,0) --(S43);
     \draw[solidLine] (D4.east) --++(15mm,0) --(S43);
     \draw[solidLine] (E4.east) --++(21mm,0) --(S42.south west);

     \draw[solidLine,-] (f4) -- node[midway,above] {$\bm{E_{a}}$} (S42);

     \draw[solidLine] (S41) -- (Kp);
     \draw[solidLine] (K1) -- (A1);
     \draw[solidLine] (K2) -- (B1);
     \draw[solidLine] (K3) -- (C1);
     \draw[solidLine] (K4) -- (D1);

      \draw[dashLine] (K5) -- (c4);
\end{tikzpicture}
\end{document}

I've left the names of the nodes so you can easily modify the code. Remove them once you done with the code.

  • 1
    for my tired eyes the texts in input rectangle as well in colored object is to small and not enough contrasted. Both should be slightly bigger and have bigger inner separation. And by the waay: your code can become shorter if you instead definition of solidLine/.style use every path/style = {...} and omit options solidLine at all lines as well option very thick in nodes definitions. In dashed lines only add option dashed ... – Zarko Nov 22 '15 at 10:34
  • @Zarko, thank you for your invaluable feedback. True it wasn't a perfect solution. Regarding colored blocks, these are names of nodes, I do suggest the OP to remove them for the final compilation. – CroCo Nov 22 '15 at 20:13
  • @H.Milad, you are welcome. – CroCo Nov 22 '15 at 20:13
0

The name of the big outer node which draws the Thalamus box is just Thalamus:

\node[draw,fit=(#2-c1) (#2-c2) (#2-c3) (#2-c4) (#2-tt), red](#2){};

draws the big node's box. The name of the node is (#2) which is the second argument you give when drawing it:

\bloc{(0,0)}{Thalamus} %the position of box 1

So Thalamus is the name you need to connect to in this case:

 \draw [->, thick] (Thalamus) |- (Amygdala-c5);

The |- means go down-and-across rather than in a diagonal line i.e. not as the crow flies.

Thalamus to Amygdala

Complete code:

\documentclass[border=10pt,tikz]{standalone}
\usetikzlibrary{calc,positioning,fit}

\begin{document}
% rpapa's code is the basis for this: http://tex.stackexchange.com/a/279011/
\newcommand{\bloc}[2]{%
  \begin{scope}[shift={#1}]
    \begin{scope}[every node/.style={circle, draw, minimum size=2em, blue}]
      \node[circle, draw] (#2-c1){};
      \node[below left=1em of #2-c1](#2-c2){};
      \node[below left=1em of #2-c2](#2-c3){};
      \node[below left=1em of #2-c3](#2-c4){};
    \end{scope}
    \node[above left=1em and 0em of #2-c1, blue](#2-tt){#2};
    \node[draw,fit=(#2-c1) (#2-c2) (#2-c3) (#2-c4) (#2-tt), red](#2){};
  \end{scope}}

\newcommand{\blocwithSum}[2]{%
  \begin{scope}[shift={#1}]
    \begin{scope}[every node/.style={circle, draw, minimum size=2em, red}]
      \node[circle, draw] (#2-c1){};
      \node[below left=1em of #2-c1](#2-c2){};
      \node[below left=1em of #2-c2](#2-c3){};
      \node[below left=1em of #2-c3](#2-c4){};
      \node[below right=2em and 1em of #2-c1, blue](#2-sum){\large $\Sigma$};
    \end{scope}
    \node[above left=1em and 0em of #2-c1, red](#2-tt){#2};
    \node[draw,fit=(#2-c1) (#2-c2) (#2-c3) (#2-c4) (#2-tt) (#2-sum), blue](#2){};
    \begin{scope}[draw=red, thick, ->]
      \draw (#2-c1)-|(#2-sum);
      \draw (#2-c2)--++(2em,0) --(#2-sum);
      \draw (#2-c3)--++(2em,0) --(#2-sum);
      \draw (#2-c4)-|(#2-sum);
    \end{scope}
  \end{scope}}

\newcommand{\blocwithz}[2]{%
  \begin{scope}[shift={#1}]
    \begin{scope}[every node/.style={circle, draw, minimum size=2em, cyan}]
      \node[circle, draw] (#2-c1){};
      \node[below left=1em of #2-c1](#2-c2){};%to draw circles
      \node[below left=1em of #2-c2](#2-c3){};
      \node[below left=1em of #2-c3](#2-c4){};
      \node[below left=1 em of #2-c4](#2-c5){};
      \node[below right=2em and 1em of #2-c1][red](#2-sum){\large $\Sigma$};%to draw Sum
      % \node[below right=2em and 0 em of#2-sum](#2-sums){\large$\Sigma$};
    \end{scope}
    \node[above left=1em and 0em of #2-c1, cyan][cyan](#2-tt){#2}; %to label the  box name Amagydala
    \node[draw,fit=(#2-c1) (#2-c2) (#2-c3) (#2-c4) (#2-c5) (#2-tt) (#2-sum), cyan](#2){}; %to draw the box
    \begin{scope}[draw=cyan, thick, ->]
      \draw (#2-c1)-|(#2-sum);
      \draw (#2-c2)--++(2em,0) --(#2-sum);
      \draw (#2-c3)--++(2em,0) --(#2-sum);
      \draw (#2-c4)-|(#2-sum);
    \end{scope}
  \end{scope}%
}

\begin{tikzpicture}
 \bloc{(0,0)}{Thalamus} %the position of box 1

 \bloc{(4cm,0)}{Sensory Cortex} %the position of box 2

 \blocwithSum{(9cm,0)}{Orbitofrontal Cortex}  %the position of box 3

 \blocwithz{(4cm,-7cm)}{Amygdala} % the position of box 4

 \foreach \ii in{1,2,3,4} {
   \node[draw][red](E\ii) at (Thalamus-c\ii-|-5,0){$S_{\ii}$};%to draw the inputs stimulus and their position
   \draw[->,thick][blue]  (E\ii)-- (Thalamus-c\ii);
   \draw[->,thick] [red](Thalamus-c\ii) -- (Sensory Cortex-c\ii);
   \draw[->,thick] [blue] (Sensory Cortex-c\ii) --  (Orbitofrontal Cortex-c\ii);
   \draw[->,thick] [red] (Sensory Cortex-c\ii) --  (Amygdala-c\ii);
   %\draw[->,thick] [red] (g) --  (Amygdala-c\ii);
 }
 \draw [->, thick] (Thalamus) |- (Amygdala-c5);
\end{tikzpicture}
\end{document}
  • Thank you Cfr , you guide me how I can figure the frame of the box of Thalamus that I can draw connection line to the circle in Amygdala box. – H.Milad Nov 22 '15 at 18:16
  • @H.Milad Note that if you shift the Amygdala box a bit to the right, you can use the |- trick to connect to the other circles so that the lines don't overlay the title at the top of the box. I'm glad it helped. I tried to focus on explaining the step you were having trouble with rather than just giving you code which can be helpful but can sometimes be hard to understand and adapt when you need to modify it. – cfr Nov 22 '15 at 19:13
  • I highly appreciate your help its work perfect. – H.Milad Nov 22 '15 at 20:15
  • @H.Milad Thank you - I'm glad it helped! I didn't get the |- thing at all until somebody explained it to me. I'm sure it is in the manual somewhere but the manual is very, very long and it is not always at all obvious where something might be. At least, not obvious to me :(. – cfr Nov 22 '15 at 20:50

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.