在 tikz 图片中延伸箭头

在 tikz 图片中延伸箭头

我创建了下图:

\documentclass{article}
\usepackage{tikz}
\usepackage{float}
\usetikzlibrary{positioning, quotes, arrows.meta}
\begin{document}

\tikzset{%
  every neuron/.style={
     circle,
    draw,
    minimum size=1cm
  },
  neuron missing/.style={
    draw=none, 
    scale=3.5,
    text height=0.333cm,
    execute at begin node=\color{black}$\vdots$,
    fill=none
  },
}
\begin{figure}[H]
\centering

\begin{tikzpicture}[x=1.5cm, y=1.5cm, >=stealth, scale=0.9, every node/.style={transform shape}]

\pgfmathsetmacro{\cubex}{2.5}
\pgfmathsetmacro{\cubey}{1}
\pgfmathsetmacro{\cubez}{1.5}
\draw [draw=black, every edge/.append style={draw=black, densely dashed, opacity=.5}] 
    (-2,0.5,0) coordinate (o) -- ++(-\cubex,0,0) coordinate (a) -- ++(0,-\cubey,0) coordinate (b) edge coordinate [pos=1] (g) ++(0,0,-\cubez)  -- ++(\cubex,0,0) coordinate (c) -- cycle
    (o) -- ++(0,0,-\cubez) coordinate (d) -- ++(0,-\cubey,0) coordinate (e) edge (g) -- (c) -- cycle
    (o) -- (a) -- ++(0,0,-\cubez) coordinate (f) edge (g) -- (d) -- cycle node[pos=2] {data};
\path [every edge/.append style={draw=black, |-|}]
    (b) +(0,-5pt) coordinate (b1) edge ["t"'] (b1 -| c)
    (b) +(-5pt,0) coordinate (b2) edge ["i"] (b2 |- a)
    (c) +(3.5pt,-3.5pt) coordinate (c2) edge ["k"'] ([xshift=3.5pt,yshift=-3.5pt]e)
    ;

\foreach \m/\l [count=\y] in {1,2,missing,3}
  \node [every neuron/.try, neuron \m/.try] (input-\m) at (0,2.5-\y) {};

\foreach \m [count=\y] in {1,missing,2}
  \node [fill=black!50, every neuron/.try, neuron \m/.try ] (hidden-\m) at (2,2.2-\y*1.1) {};

\foreach \m [count=\y] in {1}
  \node [every neuron/.try, neuron \m/.try, fill=black] (output-\m) at (4,1-\y) {};
  
 \foreach \m [count=\y] in {1}
  \node [every neuron/.try, neuron \m/.try, fill=black] (nt-\m) at (4,0-\y) {};

 \foreach \m [count=\y] in {1}
  \node [every neuron/.try, neuron \m/.try, fill=black] (ew-\m) at (4,2-\y) {};

\foreach \l [count=\i] in {1,2,n}
  \draw [<-] (input-\i) -- ++(-1,0)
    node [above, midway] {$I_\l$};

\foreach \l [count=\i] in {1,m}
  \node [above] at (hidden-\i.north) {$H_\l$};


\node [above] at (ew-1.north) {$ew$};
\node [below] at (nt-1.south) {$nt$};
    

\foreach \l [count=\i] in {1}
  \draw [->] (output-\i) -- ++(1,0)
    node [above, midway] {$O_\l$};

\foreach \i in {1,...,3}
  \foreach \j in {1,...,2}
    \draw [->] (input-\i) -- (hidden-\j);

\foreach \i in {1,...,2}
  \foreach \j in {1}
    \draw [->] (hidden-\i) -- (output-\j);

\draw [->] (nt-1) -- (output-1);
\draw [->] (ew-1) -- (output-1);

\foreach \l [count=\x from 0] in {Input, Hidden, Ouput}
  \node [align=center, above] at (\x*2,2) {\l \\[-0.4em] layer};

\pgfmathsetmacro{\rectx}{8}
\pgfmathsetmacro{\recty}{0.5}
\draw[draw=black] (5.5,-0.5) rectangle (\rectx,\recty) node[pos=.5] {weights};
\draw[black, |-|, yshift=-5pt] (5.5,-0.5) --node[below]{t} (\rectx,-0.5);
\draw[black, |-|, xshift=-5pt] (5.5,-0.5) --node[left]{i} (5.5,\recty);


\end{tikzpicture}
\caption{Neural Network Structure}
\end{figure}

\end{document}

由此得到以下图片:当前的

但是,我想让左边的箭头看起来如下;即,它们应该从左侧框的中间(垂直)到达输入层,如图所示:在此处输入图片描述

答案1

添加一个额外的点来连接这三条线。我将其添加到(-1.5,0)

\foreach \l [count=\i] in {1,2,n}
  \draw [<-] (input-\i) -- ++(-1,0)node [above, midway] {$I_\l$} -- (-1.5,0);

在此处输入图片描述

相关内容