2

I want to remove the starting 'heads' from the dotted arrows I drew from coordinates to nodes. With to instead of edge they dont appear but I cant get them dotted. Any ideas?

\documentclass[tikz,border=2mm]{standalone}
\newcommand{\mym}{\mkern-1.5mu-\mkern-3mu 1}    % small minus for subscripts

\begin{document}

\begin{tikzpicture}
[   cnode/.style={draw=black,fill=#1,minimum width=3mm,circle},
]
    % draw 3 timesteps
    \foreach \x in {1,...,3}
    {   
        % nodes input hidden and output
        \node[cnode=blue,label=180:$ x_{\x}$] (x-\x) at ({3.3*\x-div(\x,4)},0) {};
        \node[cnode=gray,label=90:$ v^{(1)}_{\x}$] (p-\x) at ({3.3*\x-div(\x,4)},2) {};
        \node[cnode=orange,label=90:$ r^{(1)}_{\x}$] (q-\x) at ({3.3*\x-div(\x,4)},4) {};
        \node[cnode=gray,label=90:$ v^{(2)}_{\x}$] (r-\x) at ({3.3*\x-div(\x,4)},6) {};
        \node[cnode=orange,label=90:$~~r^{(n\mym)}_{\x}$] (h-\x) at ({3.3*\x-div(\x,4)},8) {};
        \node[cnode=gray,label=90:$ v^{(n\mym)}_{\x}~$] (g-\x) at ({3.3*\x-div(\x,4)},10) {};
        \node[cnode=red, label=90:$ x^{(n)}_{\x}$] (s-\x) at ({3.3*\x-div(\x,4)},13) {};
        % cords for nowhere arrows
        \coordinate[left of=r-\x] (n-\x);
        \coordinate[right of=h-\x] (m-\x);
        \draw [->](q-\x) edge [dotted, bend left=30] (n-\x); 
        \draw [->](m-\x) edge [dotted, bend right=30] (g-\x); 
        % draw weights
        \draw [->](x-\x) to [bend right=45] node[right,pos=0.6] {$ \omega_v^{(1)}$} (p-\x);    
        \draw [->](x-\x) to [bend left=45] node[left,pos=0.7] {$ \omega_r^{(1)}$} (q-\x);          
        \draw [->](p-\x) to [bend right=45] node[right,pos=0.75] {$ \omega_v^{(2)}$} (r-\x);            
        \draw [->](h-\x) to [bend left=45] node[left,pos=0.7] {$ \omega_r^{(n)}$} (s-\x);
        \draw [->](g-\x) to [bend right=45] node[right,pos=0.7] {$ \omega_v^{(n)}$} (s-\x);   
        \node at ({3.3*\x-div(\x,4)},7.4) {$\vdots$};
    }
    % add last input \tau
    \node[cnode=blue,label=180:$ x_{\tau}$] (x-4) at (14,0) {};
    \node[cnode=gray,label=90:$ v^{(1)}_{\tau}$] (p-4) at (14,2) {};
    \node[cnode=orange,label=90:$ r^{(1)}_{\tau}$] (q-4) at (14,4) {};
    \node[cnode=gray,label=90:$ v^{(2)}_{\tau}$] (r-4) at (14,6) {};
    \node[cnode=orange,label=90:$~~r^{(n\mym)}_{\tau}$] (h-4) at (14,8) {};
    \node[cnode=gray,label=90:$ v^{(n\mym)}_{\tau}~$] (g-4) at (14,10) {};
    \node[cnode=red, label=90:$ x^{(n)}_{\tau}$] (s-4) at (14,13) {};
    \draw [->](x-4) to [bend right=45] node[right,pos=0.6] {$ \omega_v^{(1)}$} (p-4);        
    \draw [->](x-4) to [bend left=45] node[left,pos=0.7] {$ \omega_r^{(1)}$} (q-4);        
    \draw [->](p-4) to [bend right=45] node[right,pos=0.75] {$ \omega_v^{(2)}$} (r-4);
    \draw [->](h-4) to [bend left=45] node[left,pos=0.7] {$ \omega_r^{(n)}$} (s-4);    
    \draw [->](g-4) to [bend right=45] node[right,pos=0.7] {$ \omega_v^{(n)}$} (s-4);  
    \node at (12,2) {$\cdots$};
    \node at (12,4) {$\cdots$};
    \node at (12,6) {$\cdots$};
    \node at (12,8) {$\cdots$};
    \node at (12,10) {$\cdots$};
    \node at (14,7.4) {$\vdots$};   
   % draw recurrent weights
    \foreach[evaluate=\x as \xnext using int(\x+1)] \x in {1,2}
    {
        \draw [->](p-\x) -- node[above,pos=0.4] {$ \nu_v^{(1)}$} (p-\xnext);   
        \draw [<-](q-\x) -- node[above,pos=0.55] {$ \nu_r^{(1)}$} (q-\xnext);  
        \draw [->](r-\x) -- node[above,pos=0.4] {$ \nu_v^{(2)}$} (r-\xnext);   
        \draw [->](h-\x) -- node[above,pos=0.55] {$ \nu_r^{(n\mym)}$} (h-\xnext); 
        \draw [<-](g-\x) -- node[above,pos=0.4] {$ \nu_v^{(n\mym)}$} (g-\xnext);     
    }
    % dotted arrows for last timestep
    \coordinate[left of=r-4] (n-4);
    \coordinate[right of=h-4] (m-4);
    \draw [->](q-4) edge [dotted, bend left=30] (n-4); 
    \draw [->](m-4) edge [dotted, bend right=30] (g-4); 

\end{tikzpicture}

\end{document}

enter image description here

EDIT: Additional Question: how to move the starting points of those arrows slightly upwards or downwards?

With @SchrödingersCat s Hint that was possible by using two coordinates for each starting point like this:

\coordinate[left= 0.8 of r-\x] (N-\x);
\coordinate[right= 0.8 of h-\x] (M-\x);
\coordinate[above= 0.3 of N-\x] (n-\x);
\coordinate[below= 0.3 of M-\x] (m-\x);
\draw (q-\x) edge [dotted, bend left=30, ->] (n-\x); 
\draw (m-\x) edge [dotted, bend right=30, ->] (g-\x); 
  • 2
    Put the arrow in the edges: \draw q-4) edge [dotted, bend left=30,->] (n-4); instead of \draw [->](q-4) edge [dotted, bend left=30] (n-4); . Explanation: an edge starts a new path so technically you draw two paths, hence the excess arrow hear. Alternatively you can say \draw [dotted, ->](q-4) to[bend left=30] (n-4);. – Schrödinger's cat Sep 4 at 18:53
  • perfect, thank you thats it! Sometimes tikz can be simple. May I ask you how you know that? Or better is there any good literature / documentary on Tikz where could look such things up? – Quastiat Sep 4 at 18:58
  • also do you happen to know, how to move the \coordinates slighlty upwards/downwards from where they are? – Quastiat Sep 4 at 19:05
  • Which coordinates should be moved where? – Schrödinger's cat Sep 4 at 19:09
  • the \coordinate[left of=r-\x] (n-\x); from the first loop should be moved slightly higher from where they are now and \coordinate[right of=h-\x] (m-\x); on the other hand slightly lower – Quastiat Sep 5 at 8:56
2

An edge starts a separate path. So if say

 \draw [->](q-4) edge [dotted, bend left=30] (n-4); 

TikZ sees two paths, one is just the point (q-4), and the other one is the edge, and the arrow head gets applied to both. There are two ways you can solve this: either replace the above by

 \draw q-4) edge [dotted, bend left=30,->] (n-4);

i.e. move the arrow to the edge, or replace edge by to

 \draw [dotted, ->](q-4) to[bend left=30] (n-4);

As you see, you need also to move dotted to the options of \draw in that case.

I personally am not a big fan of edges, nor or quotes, so I'd go for the second option. (Why am I not a fan? This is because paths can be used for intersections, recycled with save path and use path etc, but with edges this is more complicated.)

\documentclass[tikz,border=2mm]{standalone}
\newcommand{\mym}{\mkern-1.5mu-\mkern-3mu 1}    % small minus for subscripts

\begin{document}

\begin{tikzpicture}
[   cnode/.style={draw=black,fill=#1,minimum width=3mm,circle},
]
    % draw 3 timesteps
    \foreach \x in {1,...,3}
    {   
        % nodes input hidden and output
        \node[cnode=blue,label=180:$ x_{\x}$] (x-\x) at ({3.3*\x-div(\x,4)},0) {};
        \node[cnode=gray,label=90:$ v^{(1)}_{\x}$] (p-\x) at ({3.3*\x-div(\x,4)},2) {};
        \node[cnode=orange,label=90:$ r^{(1)}_{\x}$] (q-\x) at ({3.3*\x-div(\x,4)},4) {};
        \node[cnode=gray,label=90:$ v^{(2)}_{\x}$] (r-\x) at ({3.3*\x-div(\x,4)},6) {};
        \node[cnode=orange,label=90:$~~r^{(n\mym)}_{\x}$] (h-\x) at ({3.3*\x-div(\x,4)},8) {};
        \node[cnode=gray,label=90:$ v^{(n\mym)}_{\x}~$] (g-\x) at ({3.3*\x-div(\x,4)},10) {};
        \node[cnode=red, label=90:$ x^{(n)}_{\x}$] (s-\x) at ({3.3*\x-div(\x,4)},13) {};
        % cords for nowhere arrows
        \coordinate[left of=r-\x] (n-\x);
        \coordinate[right of=h-\x] (m-\x);
        \draw [dotted,->](q-\x) to[bend left=30] (n-\x); 
        \draw [dotted,->](m-\x) to[bend right=30] (g-\x); 
        % draw weights
        \draw [->](x-\x) to [bend right=45] node[right,pos=0.6] {$ \omega_v^{(1)}$} (p-\x);    
        \draw [->](x-\x) to [bend left=45] node[left,pos=0.7] {$ \omega_r^{(1)}$} (q-\x);          
        \draw [->](p-\x) to [bend right=45] node[right,pos=0.75] {$ \omega_v^{(2)}$} (r-\x);            
        \draw [->](h-\x) to [bend left=45] node[left,pos=0.7] {$ \omega_r^{(n)}$} (s-\x);
        \draw [->](g-\x) to [bend right=45] node[right,pos=0.7] {$ \omega_v^{(n)}$} (s-\x);   
        \node at ({3.3*\x-div(\x,4)},7.4) {$\vdots$};
    }
    % add last input \tau
    \node[cnode=blue,label=180:$ x_{\tau}$] (x-4) at (14,0) {};
    \node[cnode=gray,label=90:$ v^{(1)}_{\tau}$] (p-4) at (14,2) {};
    \node[cnode=orange,label=90:$ r^{(1)}_{\tau}$] (q-4) at (14,4) {};
    \node[cnode=gray,label=90:$ v^{(2)}_{\tau}$] (r-4) at (14,6) {};
    \node[cnode=orange,label=90:$~~r^{(n\mym)}_{\tau}$] (h-4) at (14,8) {};
    \node[cnode=gray,label=90:$ v^{(n\mym)}_{\tau}~$] (g-4) at (14,10) {};
    \node[cnode=red, label=90:$ x^{(n)}_{\tau}$] (s-4) at (14,13) {};
    \draw [->](x-4) to [bend right=45] node[right,pos=0.6] {$ \omega_v^{(1)}$} (p-4);        
    \draw [->](x-4) to [bend left=45] node[left,pos=0.7] {$ \omega_r^{(1)}$} (q-4);        
    \draw [->](p-4) to [bend right=45] node[right,pos=0.75] {$ \omega_v^{(2)}$} (r-4);
    \draw [->](h-4) to [bend left=45] node[left,pos=0.7] {$ \omega_r^{(n)}$} (s-4);    
    \draw [->](g-4) to [bend right=45] node[right,pos=0.7] {$ \omega_v^{(n)}$} (s-4);  
    \node at (12,2) {$\cdots$};
    \node at (12,4) {$\cdots$};
    \node at (12,6) {$\cdots$};
    \node at (12,8) {$\cdots$};
    \node at (12,10) {$\cdots$};
    \node at (14,7.4) {$\vdots$};   
   % draw recurrent weights
    \foreach[evaluate=\x as \xnext using int(\x+1)] \x in {1,2}
    {
        \draw [->](p-\x) -- node[above,pos=0.4] {$ \nu_v^{(1)}$} (p-\xnext);   
        \draw [<-](q-\x) -- node[above,pos=0.55] {$ \nu_r^{(1)}$} (q-\xnext);  
        \draw [->](r-\x) -- node[above,pos=0.4] {$ \nu_v^{(2)}$} (r-\xnext);   
        \draw [->](h-\x) -- node[above,pos=0.55] {$ \nu_r^{(n\mym)}$} (h-\xnext); 
        \draw [<-](g-\x) -- node[above,pos=0.4] {$ \nu_v^{(n\mym)}$} (g-\xnext);     
    }
    % dotted arrows for last timestep
    \coordinate[left of=r-4] (n-4);
    \coordinate[right of=h-4] (m-4);
    \draw [dotted,->](q-4) to[ bend left=30] (n-4); 
    \draw [dotted,->](m-4) to[ bend right=30] (g-4); 

\end{tikzpicture}

\end{document}

enter image description here

Where is that all documented? In the pgfmanual. It is, of course, true that the pgfmanual is not very short, so you can ask questions here or just browse through the question. Your question has already been asked, e.g. here, but I admit it is only easy to find if you already know the answer. If someone wants to close this as a duplicate, I will be happy to remove this post.

  • thanks a lot again! Yeah I figured somebody already stumpled over this issue, but I couldnt find the right formulation to actually find that issue here. Besides that do you happen to know how I could move the \coordinates slightly upwards/downwards? – Quastiat Sep 4 at 19:34
  • @Quastiat Which coordinates do you want to move, and where? The main issue is that you are using the deprecated positioning mechanisms. You might want to load the positioning library, in which case \coordinate[left of=r-\x] (n-\x); would get replaced by \coordinate[left=<distance> of r-\x] (n-\x);. where the position of of has moved and you can specify the distance. (You can also specify the node distances globally with node distance=<y distance> and <x distance> of just node distance=<universal distance>.) – Schrödinger's cat Sep 4 at 20:32
  • Alright thank you i will try the first approach with an added ´above=<distance> of´ – Quastiat Sep 5 at 8:58
  • Alright so apparently its not possible to combine two of those left=<dist> of arguments right? then I could only use the explicit coordinates I guess. I dont really get your remark in brackets, does that mean I should declare node distance = (-1,-1) and then use left=node distance of (h-0)? – Quastiat Sep 6 at 15:08
  • @Quastiat It is hard for me to see what you have tried. How about you append the code to your question that it is clear what you are referring to? – Schrödinger's cat Sep 6 at 15:14
2

I quote the TikZ 3.1.4b manual pages 253-254

The edge operation works like a to operation that is added after the main path has been drawn, much like a node is added after the main path has been drawn. This allows each edge to have a different appearance. As the node operation, an edge temporarily suspends the construction of the current path and a new path p is constructed. This new path p will be drawn after the main path has been drawn. Note that p can be totally different from the main path with respect to its options.

So, it is enough to replace the operation \draw by the operation \path which will ultimately only trace the path once. It is well built twice, but it is traced only once.

% replace draw by path
        \path [->,blue](m-\x) edge [dotted, bend right=30] (g-\x); 

screenshot

\documentclass[tikz,border=2mm]{standalone}
\newcommand{\mym}{\mkern-1.5mu-\mkern-3mu 1}    % small minus for subscripts

\begin{document}

\begin{tikzpicture}
[   cnode/.style={draw=black,fill=#1,minimum width=3mm,circle},
]
    % draw 3 timesteps
    \foreach \x in {1,...,3}
    {   
        % nodes input hidden and output
        \node[cnode=blue,label=180:$ x_{\x}$] (x-\x) at ({3.3*\x-div(\x,4)},0) {};
        \node[cnode=gray,label=90:$ v^{(1)}_{\x}$] (p-\x) at ({3.3*\x-div(\x,4)},2) {};
        \node[cnode=orange,label=90:$ r^{(1)}_{\x}$] (q-\x) at ({3.3*\x-div(\x,4)},4) {};
        \node[cnode=gray,label=90:$ v^{(2)}_{\x}$] (r-\x) at ({3.3*\x-div(\x,4)},6) {};
        \node[cnode=orange,label=90:$~~r^{(n\mym)}_{\x}$] (h-\x) at ({3.3*\x-div(\x,4)},8) {};
        \node[cnode=gray,label=90:$ v^{(n\mym)}_{\x}~$] (g-\x) at ({3.3*\x-div(\x,4)},10) {};
        \node[cnode=red, label=90:$ x^{(n)}_{\x}$] (s-\x) at ({3.3*\x-div(\x,4)},13) {};
        % cords for nowhere arrows
        \coordinate[left of=r-\x] (n-\x);
        \coordinate[right of=h-\x] (m-\x);
        \draw [->](q-\x) edge [dotted, bend left=30] (n-\x); 

        % replace draw by path
        \path [->,blue](m-\x) edge [dotted, bend right=30] (g-\x); 
        % draw weights
        \draw [->](x-\x) to [bend right=45] node[right,pos=0.6] {$ \omega_v^{(1)}$} (p-\x);    
        \draw [->](x-\x) to [bend left=45] node[left,pos=0.7] {$ \omega_r^{(1)}$} (q-\x);          
        \draw [->](p-\x) to [bend right=45] node[right,pos=0.75] {$ \omega_v^{(2)}$} (r-\x);            
        \draw [->](h-\x) to [bend left=45] node[left,pos=0.7] {$ \omega_r^{(n)}$} (s-\x);
        \draw [->](g-\x) to [bend right=45] node[right,pos=0.7] {$ \omega_v^{(n)}$} (s-\x);   
        \node at ({3.3*\x-div(\x,4)},7.4) {$\vdots$};
    }
    % add last input \tau
    \node[cnode=blue,label=180:$ x_{\tau}$] (x-4) at (14,0) {};
    \node[cnode=gray,label=90:$ v^{(1)}_{\tau}$] (p-4) at (14,2) {};
    \node[cnode=orange,label=90:$ r^{(1)}_{\tau}$] (q-4) at (14,4) {};
    \node[cnode=gray,label=90:$ v^{(2)}_{\tau}$] (r-4) at (14,6) {};
    \node[cnode=orange,label=90:$~~r^{(n\mym)}_{\tau}$] (h-4) at (14,8) {};
    \node[cnode=gray,label=90:$ v^{(n\mym)}_{\tau}~$] (g-4) at (14,10) {};
    \node[cnode=red, label=90:$ x^{(n)}_{\tau}$] (s-4) at (14,13) {};
    \draw [->](x-4) to [bend right=45] node[right,pos=0.6] {$ \omega_v^{(1)}$} (p-4);        
    \draw [->](x-4) to [bend left=45] node[left,pos=0.7] {$ \omega_r^{(1)}$} (q-4);        
    \draw [->](p-4) to [bend right=45] node[right,pos=0.75] {$ \omega_v^{(2)}$} (r-4);
    \draw [->](h-4) to [bend left=45] node[left,pos=0.7] {$ \omega_r^{(n)}$} (s-4);    
    \draw [->](g-4) to [bend right=45] node[right,pos=0.7] {$ \omega_v^{(n)}$} (s-4);  
    \node at (12,2) {$\cdots$};
    \node at (12,4) {$\cdots$};
    \node at (12,6) {$\cdots$};
    \node at (12,8) {$\cdots$};
    \node at (12,10) {$\cdots$};
    \node at (14,7.4) {$\vdots$};   
   % draw recurrent weights
    \foreach[evaluate=\x as \xnext using int(\x+1)] \x in {1,2}
    {
        \draw [->](p-\x) -- node[above,pos=0.4] {$ \nu_v^{(1)}$} (p-\xnext);   
        \draw [<-](q-\x) -- node[above,pos=0.55] {$ \nu_r^{(1)}$} (q-\xnext);  
        \draw [->](r-\x) -- node[above,pos=0.4] {$ \nu_v^{(2)}$} (r-\xnext);   
        \draw [->](h-\x) -- node[above,pos=0.55] {$ \nu_r^{(n\mym)}$} (h-\xnext); 
        \draw [<-](g-\x) -- node[above,pos=0.4] {$ \nu_v^{(n\mym)}$} (g-\xnext);     
    }
    % dotted arrows for last timestep
    \coordinate[left of=r-4] (n-4);
    \coordinate[right of=h-4] (m-4);
    \draw [->](q-4) edge [dotted, bend left=30] (n-4); 
    % replace draw by path
    \path [->](m-4) edge [dotted, bend right=30] (g-4); 
\end{tikzpicture}

\end{document}
  • 1
    thank you that works as well! – Quastiat Sep 6 at 14:51
  • 1
    @Quastiat There is another way to do the same : add the tips=proper option to the tikzpicture environment: \begin{tikzpicture} [cnode/.style={draw=black,fill=#1,minimum width=3mm,circle},tips=proper] – AndréC Sep 6 at 16:03
  • 1
    @AndréC Always very good in particular with tikz-pgf. – Sebastiano Sep 6 at 20:13

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.