我想从我绘制的从坐标到节点的虚线箭头中删除起始“头部”。用to
代替edge
它们不会出现,但我无法将它们变成虚线。有什么想法吗?
\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}
编辑: 附加问题:如何将这些箭头的起点稍微向上或向下移动?
使用@SchrödingersCat 的提示,可以通过为每个起点使用两个坐标来实现,如下所示:
\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);
答案1
一条边开始一条单独的路径。因此,如果说
\draw [->](q-4) edge [dotted, bend left=30] (n-4);
钛钾Z 看到两条路径,一条只是点(q-4)
,另一条是边,箭头会应用于这两条路径。有两种方法可以解决这个问题:要么将上面的替换为
\draw q-4) edge [dotted, bend left=30,->] (n-4);
即将箭头移到边缘,或替换edge
为to
\draw [dotted, ->](q-4) to[bend left=30] (n-4);
如您所见,在这种情况下您还需要转到dotted
选项\draw
。
我个人不太喜欢edge
s 或quotes
,所以我会选择第二种选择。(为什么我不喜欢?这是因为路径可以用于交叉点,用save path
和use path
等回收,但用edges
这个更复杂。)
\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}
所有这些都记录在哪里?在pgfmanual
。当然, 确实不是pgfmanual
很短,所以你可以在这里提问,或者只是浏览一下问题。你的问题已经被问过了,例如这里,但我承认,只有当您已经知道答案时,才容易找到它。如果有人想将此作为重复关闭,我很乐意删除此帖子。
答案2
我引用了 TikZ 3.1.4b 手册第 253-254 页
这边缘操作就像到在绘制主路径后添加的操作,就像在绘制主路径后添加节点一样。这允许每个边缘以具有不同的外观。作为节点操作,边缘暂时停止当前路径的构建,并构建一条新路径 p。这条新路径 p 将在主路径绘制完成后绘制。请注意,p 的选项可能与主路径完全不同。
\draw
因此,用最终只会跟踪一次路径的操作替换该操作就足够了\path
。它构建了两次,但只跟踪了一次。
% replace draw by path
\path [->,blue](m-\x) edge [dotted, bend right=30] (g-\x);
\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}