Tikz Arrow 라벨 위치 지정 문제

Tikz Arrow 라벨 위치 지정 문제

다음 tikz 사진이 있습니다. 시간이 지남에 따라 순환 신경망이 펼쳐지는 것을 묘사하는 Tikz 그림

\usepackage{tikz}
\usetikzlibrary{positioning, chains}
\begin{document}
\begin{tikzpicture}[
item/.style={circle,draw,thick,align=center, minimum size=1.2cm},
hidden/.style={item,on chain,join}]

 \begin{scope}[start chain=going right,nodes=hidden,every
 join/.style={-latex,very thick},local bounding box=chain]
 \draw node (A0) {$h_0$} node (A1) {$h_1$} node (A2) {$h_2$} node[xshift=2em] (At)
 {$h_t$};
 \end{scope}
 \node[left=1em of chain,scale=2] (eq) {$=$};
 \node[left=2em of eq,item] (AL) {$h$};
 \path (AL.west) ++ (-1em,2em) coordinate (aux);
 \draw[very thick,-latex,rounded corners] (AL.east) -| ++ (1em,2em) -- (aux)
 |- (AL.west) node[midway, left] {$U$};
 \foreach \X in {0,1,2,t}
 {\draw[very thick,-latex] (A\X.north) -- ++ (0,2em) node[midway, right] {$V$}
 node[above,item,fill=gray!10] (h\X) {$\hat{y}_\X$};
 \draw[very thick,latex-] (A\X.south) -- ++ (0,-2em) node[midway, right] {$W$}
 node[below,item,fill=gray!10] (x\X) {$x_\X$};
 \path (A\X.east) -- (A\X -| At.west) node[midway, above] {$U$};
}
 
 \draw[white,line width=0.8ex] (AL.north) -- ++ (0,1.9em);
 \draw[very thick,-latex] (AL.north) -- ++ (0,2em) node[midway, right] {$V$}
 node[above,item,fill=gray!10] {$\hat{y}_t$};
 \draw[very thick,latex-] (AL.south) -- ++ (0,-2em) node[midway, right] {$W$}
 node[below,item,fill=gray!10] {$x_t$};
 \path (x2) -- (xt) node[midway,scale=2,font=\bfseries] {\dots};
\end{tikzpicture}
\end{document}

U해당 화살표와 정렬되도록 위치를 지정할 수 없습니다 . 누군가 나에게 올바른 방향을 알려줄 수 있습니까?

답변1

첫 번째의 경우 U코드를 -- (aux) --++(0em,-2em) node[midway, left] {$U$} -- (AL.west);경로에 사용하여 U왼쪽 선분의 중간에 배치할 수 있습니다.

다른 U의 경우 다음 코드를 사용하여 각각을 U별도로 배치할 수 있습니다.

\path (A0.east) -- (A1.west) node[midway, above] {$U$};
\path (A1.east) -- (A2.west) node[midway, above] {$U$};
\path (A2.east) -- (At.west) node[midway, above] {$U$};

그런 다음 선을 \path (A\X.east) -- (A\X -| At.west) node[midway, above] {$U$};제거할 수 있습니다.

답변2

올바른 배치 가장자리 레이블이 있는 조금 더 짧고 (훨씬 더) 명확한 코드입니다. 아래의 OP 코드 MWE와 비교하면 추가 사용 라이브러리 arrows.meta(더 좋은 화살표의 경우), ext.paths.orth(직교 / r-lr/ 화살표 유형의 경우) 및 quotes(가장자리 레이블)의 경우:

\documentclass[margin=3mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
                chains,
                ext.paths.ortho,    % defined in the tikz-ext package
                positioning,
                quotes}

\begin{document}
    \begin{tikzpicture}[
  start chain = going right,
   arr/.style = {-{Straight Barb[scale=0.8]}, semithick},
  item/.style = {circle, draw, thick, fill=gray!30, minimum size=11mm},
hidden/.style = {item, fill=none,
                 on chain, join=by arr},
                        ]
% from right to left
    \foreach \i in {0,1,2,t}
{
\node (A\i) [hidden] {$h_\i$};
\node (B\i) [item, above=of A\i]  {$\hat{y}_\i$};
\node (C\i) [item, below=of A\i]  {$x_\i$};
\draw[arr]  (A\i) to["$V$" '] (B\i);
\draw[arr]  (A\i) to["$W$"] (C\i);
}
\path   (A0) to ["$V$"] (A1) to ["$V$"] (A2) to ["$V$"] (At);
\draw[thick,densely dashed, white, shorten >=2mm, shorten <=2mm]   (A2) to (At);
% equals sign 
\node (eq) [left=1em of A0, scale=2] {$=$};
% general/common symbol
\node (AL) [item, fill=none, left=2em of eq,] {$h$};
\node (Y) [item, above=of AL]  {$\hat{y}_t$};
\node (X) [item, below=of AL]  {$x_t$};
\draw[arr]  (AL) to["$V$" '] (Y);
\draw[arr]  (AL) to["$W$"]   (X);
\draw[arr, rounded corners]
    (AL.east) -| ++ (1em,2em) r-lr (AL) node[midway, left] {$U$};
    \end{tikzpicture}
\end{document}

여기에 이미지 설명을 입력하세요

관련 정보