沿箭头方向移动箭头处的文本

沿箭头方向移动箭头处的文本

我试图将文本放在合适的位置,并尝试使用abovebelowleft... 和等选项pos,但我做不到。我的想法是将标签移动到新的干净位置,例如:

在此处输入图片描述

这是我的代码:

\documentclass{article}
\usepackage[utf8]{inputenc}

\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{positioning,calc}
\usetikzlibrary{arrows,shapes}

\tikzset{
 % flecha
 flecha/.style={->,>=stealth',black,shorten >=1pt}, 
 % estilo circulo
 circulo/.style={circle,text=black,draw=cyan!40, fill=cyan!10, very thick, minimum size=9mm}, 
 % estilo cuadrado
 cuadrado/.style={rectangle,text=black,draw=blue!40, fill=blue!10, very thick, minimum size=6mm, minimum width=11mm}, 
 % estilo cuadrado pequeño
 cuadrado2/.style={cuadrado, minimum size=3mm, minimum width=7mm, minimum height=5mm}, 
 % estilo elipse
 elipse/.style={rectangle,rounded corners=8,text=black,draw=cyan!40, fill=cyan!10, very thick, minimum size=6mm}, 
 % cuadrado de puntos transparente
 transparente/.style={rectangle,fill=white,draw=none,text=black,minimum size=6mm}
}

\begin{document}
\begin{tikzpicture}[remember picture, overlay, shift={($(current page.west)+(5.5cm,-3cm)$)}, ->, >=stealth', shorten >=1pt, node distance=1cm, font=\scriptsize]

% G1
\node[cuadrado] (g1_1) {$(y_m)$};
\node[circulo] (g1_2) [left = 1cm of g1_1] {$y_m$};
\node[circulo] (g1_3) [right = 1cm of g1_1] {$\neg y_m$};
\node[cuadrado] (g1_4) [above left = 0.5cm of g1_2] {$y_m$};
\node[cuadrado] (g1_6) [above right = 0.5cm of g1_3] {$\neg y_m$};
\node[cuadrado] (g1_8) [above right = 0.5cm of g1_2] {$[y_m^k]$};
\node[cuadrado] (g1_9) [above left = 0.5cm of g1_3] {$[\neg y_m^k]$};
\node[cuadrado] (g1_10) [above = 0.5cm of g1_8] {$[y_m^1]$};
\node[cuadrado] (g1_11) [above = 0.5cm of g1_9] {$[\neg y_m^1]$};
\node[transparente] (g100_1) [below = 0.5cm of g1_4] {$\vdots$};
\node[transparente] (g100_2) [below = 0.5cm of g1_6] {$\vdots$};
\node[transparente] (g100_3) [below = 3.46cm of g1_2] {$\vdots$};
\node[transparente] (g100_4) [below = 3.46cm of g1_3] {$\vdots$};
\node[rectangle,text opacity=1,fill opacity=0.5,draw=none,text=black,minimum size=1mm] (g100_5) [below = -0.21cm of g1_10] {\tiny$\vdots$};
\node[rectangle,text opacity=1,fill opacity=0.5,draw=none,text=black,minimum size=1mm] (g100_6) [below = -0.21cm of g1_11] {\tiny$\vdots$};

% G2
\node[cuadrado] (g2_1) [above = 3cm of g1_1] {$(y_1)$};
\node[circulo] (g2_2) [left = 1cm of g2_1] {$y_1$};
\node[circulo] (g2_3) [right = 1cm of g2_1] {$\neg y_1$};
\node[cuadrado] (g2_4) [above left = 0.5cm of g2_2] {$y_1$};
\node[cuadrado] (g2_6) [above right = 0.5cm of g2_3] {$\neg y_1$};
\node[cuadrado] (g2_8) [above right = 0.5cm of g2_2] {$[y_1^k]$};
\node[cuadrado] (g2_9) [above left = 0.5cm of g2_3] {$[\neg y_1^k]$};
\node[cuadrado] (g2_10) [above = 0.5cm of g2_8] {$[y_1^1]$};
\node[cuadrado] (g2_11) [above = 0.5cm of g2_9] {$[\neg y_1^1]$};
\node[transparente] (g20_1) [below = 0.5cm of g2_2] {$\vdots$};
\node[transparente] (g20_2) [below = 0.5cm of g2_3] {$\vdots$};
\node[rectangle,text opacity=1,fill opacity=0.5,draw=none,text=black,minimum size=1mm] (g20_3) [below = -0.21cm of g2_10] {\tiny$\vdots$};
\node[rectangle,text opacity=1,fill opacity=0.5,draw=none,text=black,minimum size=1mm] (g20_4) [below = -0.21cm of g2_11] {\tiny$\vdots$};

% G3
\node[cuadrado] (g3_1) [above = 8cm of g1_1] {$(x_n)$};
\node[circulo] (g3_2) [left = 1cm of g3_1] {$x_n$};
\node[circulo] (g3_3) [right = 1cm of g3_1] {$\neg x_n$};
\node[cuadrado] (g3_4) [above left = 0.5cm of g3_2] {$x_n$};
\node[cuadrado] (g3_5) [below left = 0.5cm of g3_2] {$\langle x_n\rangle$};
\node[cuadrado] (g3_6) [above right = 0.5cm of g3_3] {$\neg x_n$};
\node[cuadrado] (g3_7) [below right = 0.5cm of g3_3] {$\langle \neg x_n\rangle$};
\node[cuadrado] (g3_8) [above right = 0.5cm of g3_2] {$[x_m^k]$};
\node[cuadrado] (g3_9) [above left = 0.5cm of g3_3] {$[\neg x_m^k]$};
\node[cuadrado] (g3_10) [above = 0.5cm of g3_8] {$[x_m^1]$};
\node[cuadrado] (g3_11) [above = 0.5cm of g3_9] {$[\neg x_m^1]$};
\node[rectangle,text opacity=1,fill opacity=0.5,draw=none,text=black,minimum size=1mm] (g30_1) [below = -0.21cm of g3_10] {\tiny$\vdots$};
\node[rectangle,text opacity=1,fill opacity=0.5,draw=none,text=black,minimum size=1mm] (g30_2) [below = -0.21cm of g3_11] {\tiny$\vdots$};

% G4
\node[cuadrado] (g4_1) [above = 12cm of g1_1] {$(x_1)$};
\node[circulo] (g4_2) [left = 1cm of g4_1] {$x_1$};
\node[circulo] (g4_3) [right = 1cm of g4_1] {$\neg x_1$};
\node[cuadrado] (g4_4) [above left = 0.5cm of g4_2] {$x_1$};
\node[cuadrado] (g4_5) [below left = 0.5cm of g4_2] {$\langle x_1\rangle$};
\node[cuadrado] (g4_6) [above right = 0.5cm of g4_3] {$\neg x_1$};
\node[cuadrado] (g4_7) [below right = 0.5cm of g4_3] {$\langle\neg
x_1\rangle$};
\node[cuadrado] (g4_8) [above right = 0.5cm of g4_2] {$[x_1^k]$};
\node[cuadrado] (g4_9) [above left = 0.5cm of g4_3] {$[\neg x_1^k]$};
\node[cuadrado] (g4_10) [above = 0.5cm of g4_8] {$[x_1^1]$};
\node[cuadrado] (g4_11) [above = 0.5cm of g4_9] {$[\neg x_1^1]$};
\node[transparente] (g40_1) [below = 0.5cm of g4_2] {$\vdots$};
\node[transparente] (g40_2) [below = 0.5cm of g4_3] {$\vdots$};
\node[rectangle,text opacity=1,fill opacity=0.5,draw=none,text=black,minimum size=1mm] (g40_3) [below = -0.21cm of g4_10] {\tiny$\vdots$};
\node[rectangle,text opacity=1,fill opacity=0.5,draw=none,text=black,minimum size=1mm] (g40_4) [below = -0.21cm of g4_11] {\tiny$\vdots$};

% G10
\node[circulo] (g10_1) [below = 1.5cm of g1_1] {$u_0$};
\node[cuadrado] (g10_2) [below left = 0.6cm of g10_1] {$u_0$};
\node[cuadrado] (g10_3) [below right = 0.6cm of g10_1] {$u_0 \_ u_0^,$};
\node[circulo] (g10_4) [below = 1.2cm of g10_1] {$u_0^,$};
\node[cuadrado] (g10_5) [below left = 0.6cm of g10_4] {$u_0^,$};


% G5
\node[elipse, align=center] (g5_1) [right = 1.5cm of g4_7] {$C_1$ \\ $\thinspace x_1 \vee\neg x_n\vee y_1$};
\node[transparente] (g50_1) [right = 1cm of g5_1] {$\dotsb$};
\node[circulo] (g5_2) [right = 2.4cm of g5_1] {$c_i$};
\node[transparente] (g50_2) [right = 0.8cm of g5_2] {$\dotsb$};
\node[circulo] (g5_3) [right = 2.2cm of g5_2] {$c_k$};
\node[transparente] (g5_4) [above left = 0.7cm of g5_2] {$\dotsb$};
\node[transparente] (g5_5) [above = 0.7cm of g5_2] {$\dotsb$};
\node[transparente] (g5_6) [above right = 0.7cm of g5_2] {$\dotsb$};
\node[transparente] (g5_7) [above left = 0.7cm of g5_3] {$\dotsb$};
\node[transparente] (g5_8) [above = 0.7cm of g5_3] {$\dotsb$};
\node[transparente] (g5_9) [above right = 0.7cm of g5_3] {$\dotsb$};
\node[cuadrado2] (g5_10) [below = 0.4cm of g5_1] {$[c_1]$};
\node[cuadrado2] (g5_11) [below right = 0.5cm of g5_1] {$[c_1]$};
\node[cuadrado2] (g5_12) [below left = 0.5cm of g5_2] {$[c_i]$};
\node[cuadrado2] (g5_13) [below right = 0.5cm of g5_2] {$[c_i]$};
\node[cuadrado2] (g5_14) [below left = 0.5cm of g5_3] {$[c_k]$};
\node[cuadrado2] (g5_15) [below right = 0.5cm of g5_3] {$[c_k]$};

% G6
\node[circulo] (g6_1) [below = 3cm of g5_2] {$all$};
\node[cuadrado] (g6_2) [below left = 1cm of g6_1] {$u_0 \_ all$};
\node[cuadrado] (g6_3) [below right = 1cm of g6_1] {$all \_ all^,$};
\node[circulo] (g6_4) [below = 1cm of g6_3] {$all^,$};
\node[cuadrado] (g6_5) [below = 1cm of g6_4] {$all^,$};
\node[cuadrado] (g6_6) [right = 1cm of g6_1] {$all$};

% G7
\node[circulo] (g7_1) [below = 14cm of g5_12] {$col_i$};
\node[cuadrado2] (g7_2) [above right = 0.3cm of g7_1] {$col_i$};
\node[transparente] (g70_1) [below = 1cm of g7_1] {$\dotsb$};
\node[cuadrado2] (g7_6) [left = 0.1cm of g70_1] {$[\neg x_1^k]$};
\node[transparente] (g70_2) [left = 0.03cm of g7_6] {$\dotsb$};
\node[cuadrado2] (g7_5) [left = 0.1cm of g70_2] {$[\neg x_1^1]$};
\node[cuadrado2] (g7_4) [left = 0.3cm of g7_5] {$[x_1^k]$};
\node[transparente] (g70_3) [left = 0cm of g7_4] {$\dotsb$};
\node[cuadrado2] (g7_3) [left = 0cm of g70_3] {$[x_1^1]$};
% --------------------------
\node[cuadrado2] (g7_7) [right = 0.1cm of g70_1] {$[y_m^1]$};
\node[transparente] (g70_4) [right = 0.07cm of g7_7] {$\dotsb$};
\node[cuadrado2] (g7_8) [right = 0.7cm of g7_7] {$[y_m^k]$};
\node[cuadrado2] (g7_9) [right = 0.1cm of g7_8] {$[\neg y_m^1]$};
\node[transparente] (g70_5) [right = 0.07cm of g7_9] {$\dotsb$};
\node[cuadrado2] (g7_10) [right = 0.7cm of g7_9] {$[\neg y_m^k]$};

% G8
\node[circulo] (g8_1) [below = 13cm of g5_1] {$col_1$};
\node[cuadrado2] (g8_2) [above right = 0.5cm of g8_1] {$col_1$};
\node[cuadrado2] (g8_3) [above left = 0.5cm of g8_1] {$ ? $};
\node[cuadrado2] (g8_4) [below left = 0.9cm of g8_1] {$ ? $};
\node[cuadrado2] (g8_5) [below right = 0.9cm of g8_1] {$ ? $};
\node[transparente] (g80_1) [above = 0.5cm of g8_1] {$\dotsb$};
\node[transparente] (g80_2) [below = 0.5cm of g8_1] {$\dotsb$};

% G9
\node[circulo] (g9_1) [below = 13cm of g5_3] {$col_n{}_+{}_m$};
\node[cuadrado2] (g9_2) [above right = 0.6cm of g9_1] {$col_n{}_+{}_m$};
\node[cuadrado2] (g9_3) [above left = 0.6cm of g9_1] {$ ? $};
\node[cuadrado2] (g9_4) [below left = 0.4cm of g9_1] {$ ? $};
\node[cuadrado2] (g9_5) [below right = 0.4cm of g9_1] {$ ? $};
\node[transparente] (g90_1) [above = 0.6cm of g9_1] {$\dotsb$};
\node[transparente] (g90_2) [below = 0.5cm of g9_1] {$\dotsb$};



\path   
% G1
    (g1_2) 
        edge [below] node {k} (g1_1)
        edge [left, pos=0.3] node {n} (g1_4)
        edge [left, pos=0.5] node {1} (g1_8)
        edge [bend left, left, pos=0.5] node {1} (g1_10)
    (g1_3) 
        edge [below] node {k} (g1_1)
        edge [right, pos=0.3] node {n} (g1_6)
        edge [right, pos=0.5] node {1} (g1_9)
        edge [bend right, right, pos=0.5] node {1} (g1_11)
% G2
    (g2_2) 
        edge [below] node {k} (g2_1)
        edge [left, pos=0.3] node {n} (g2_4)
        edge [left, pos=0.5] node {1} (g2_8)
        edge [bend left, left, pos=0.5] node {1} (g2_10)
    (g2_3) 
        edge [below] node {k} (g2_1)
        edge [right, pos=0.3] node {n} (g2_6)
        edge [right, pos=0.5] node {1} (g2_9)
        edge [bend right, right, pos=0.5] node {1} (g2_11)
% G3
    (g3_2) 
        edge [below] node {k+1} (g3_1)
        edge [left, pos=0.3] node {n-1} (g3_4)
        edge [left, pos=0.2] node {1} (g3_5)
        edge [left, pos=0.5] node {1} (g3_8)
        edge [bend left, left, pos=0.5] node {1} (g3_10)
    (g3_3) 
        edge [below] node {k+1} (g3_1)
        edge [right, pos=0.3] node {n-1} (g3_6)
        edge [right, pos=0.2] node {1} (g3_7)
        edge [right, pos=0.5] node {1} (g3_9)
        edge [bend right, right, pos=0.5] node {1} (g3_11)
% G4
    (g4_2) 
        edge [below] node {k+1} (g4_1)
        edge [left, pos=0.3] node {n-1} (g4_4)
        edge [left, pos=0.2] node {1} (g4_5)
        edge [left, pos=0.5] node {1} (g4_8)
        edge [bend left, left, pos=0.5] node {1} (g4_10)
    (g4_3) 
        edge [below] node {k+1} (g4_1)
        edge [right, pos=0.3] node {n-1} (g4_6)
        edge [right, pos=0.2] node {1} (g4_7)
        edge [right, pos=0.5] node {1} (g4_9)
        edge [bend right, right, pos=0.5] node {1} (g4_11)
% G10
    (g10_1) 
        edge [above  left, pos=0.5] node {k+1} (g10_2)
        edge [below  left, pos=0.5] node {n} (g10_3)
    (g10_4) 
        edge [above left, pos=0.4] node {n+2} (g10_3)
        edge [below right, pos=0.5] node {k} (g10_5)
% G5
    (g5_1)  
        edge [left, pos=0.5] node {M-1} (g5_10)
        edge [above right, pos=0.7] node {M-1} (g5_11)
    (g5_2)  
        edge [right, pos=0.8] node {2n-2} (g5_4)
        edge [right, pos=0.6] node {2n-2} (g5_5)
        edge [right, pos=0.4] node {2n-2} (g5_6)
        edge [above left, pos=0.7] node {M-1} (g5_12)
        edge [above right, pos=0.7] node {M-1} (g5_13)
    (g5_3)  
        edge [right, pos=0.8] node {2n-2} (g5_7)
        edge [right, pos=0.6] node {2n-2} (g5_8)
        edge [right, pos=0.4] node {2n-2} (g5_9)
        edge [above left, pos=0.7] node {M-1} (g5_14)
        edge [above right, pos=0.7] node {M-1} (g5_15)
% G6
    (g6_1)  
        edge [above left, pos=0.6] node {1} (g6_2)
        edge [above right, pos=0.6] node {k+3} (g6_3)
        edge [above, pos=0.5] node {n} (g6_6)
        edge [right, pos=0.5] node {1} (g5_11)
        edge [right, pos=0.5] node {1} (g5_13)
        edge [below right, pos=0.5] node {1} (g5_15)
    (g6_4)  
        edge [right, pos=0.3] node {3M} (g6_3)
        edge [right, pos=0.3] node {M} (g6_5)
% G7  
    (g7_1) 
        edge [below right, pos=0.5] node {n} (g7_2)
        edge [above, pos=0.85] node {1} (g7_3)
        edge [above, pos=0.85] node {1} (g7_4)
        edge [above, pos=0.85] node {1} (g7_5)
        edge [left, pos=0.7] node {1} (g7_6)
        edge [right, pos=0.7] node {1} (g7_7)
        edge [above, pos=0.85] node {1} (g7_8)
        edge [above, pos=0.85] node {1} (g7_9)
        edge [above, pos=0.85] node {1} (g7_10)

% G8
    (g8_1) 
        edge [below right, pos=0.5] node {n} (g8_2)
        edge [below right, pos=0.5] node {} (g8_3)
        edge [below right, pos=0.5] node {} (g8_4)
        edge [below right, pos=0.5] node {} (g8_5)
        edge [below right, pos=0.5] node {} (g80_1)
        edge [below right, pos=0.5] node {} (g80_2)
  
% G9
    (g9_1) 
        edge [below right, pos=0.5] node {n} (g9_2) 
        edge [below right, pos=0.5] node {} (g9_3)
        edge [below right, pos=0.5] node {} (g9_4)
        edge [below right, pos=0.5] node {} (g9_5)
        edge [below right, pos=0.5] node {} (g90_1)
        edge [below right, pos=0.5] node {} (g90_2)
    ;
    
\draw[flecha] (g10_1) --++ (5.6, 2.5) |- node[above right, pos=0.2] {0.5} (g6_2);
\draw[flecha] (g10_1) --++ (4.3, 2.2) -- (4.3, 10.5) -- node[above, pos=0.3] {2M-2} (g4_7);
\draw[flecha] (g10_1) --++ (4.2, 3) -- (4.2, 6.5) -- node[above, pos=0.3] {2M-2} (g3_7);
\draw[flecha] (g5_1) --++ (0, 3.8) --++ (-7.2, 0) -- node[above, pos=0.8] {2M-2} (g4_10);
\draw[flecha] (g10_1) -- ++ (-4.3, 2.2) -- (-4.3, 10.5) -- (g4_5);
\draw[flecha] (g10_1) -- ++ (-4.2, 3) -- (-4.2, 6.5) -- (g3_5);
\draw[flecha] (g10_4) -- ++ (3, -0.4) -- (4.8, 0) |- (g4_7);
\draw[flecha] (g10_4) -- ++ (3, 0.4) -- (4.7, 0) |- (g3_7);
\draw[flecha] (g10_4) -- ++ (-3, -0.4) -- (-4.8, 0) |- (g4_5);
\draw[flecha] (g10_4) -- ++ (-3, 0.4) -- (-4.7, 0) |- (g3_5);
\draw[flecha] (g5_1) -- ++ (-1.3, -0.85) -- (g3_11);
\draw[flecha] (g5_1) -- ++ (-1.25, -1) -- ++ (0, -4.2) -- ++ (-5.92, 0) -- (g2_10);
\draw[flecha] (g7_1) -- ++ (-0.2, 9) -- ++ (-2.71, 0) -- (g5_10); 
\draw[flecha] (g7_1) -- ++ (0.2, 9.4) -- ++ (-2.71, 0) --++ (0, 2) -- (g5_12);
\draw[flecha] (g7_1) -- ++ (0.35, 5) --++ (4.5, 0) --++ (0, 6.5) -- (g5_14);
 
\end{tikzpicture}
\end{document}

这三个箭头位于代码中的第 280、281 和 282 行。

答案1

回应OP的询问

我认为我知道问题所在,但不知道如何解决它。当我有一个箭头在多个坐标间移动时,当我想移动标签时,它只会以箭头的最后一部分为参考移动。例如,在这个箭头中,我无法将标签定位在箭头的开头(因为开头不是箭头的“最后一部分”):

  \draw[flecha] (g7_1) -- ++ (-0.2, 9) -- ++ (-2.71, 0) -- node[below right, pos=0.9] {1} (g5_10);

提出的解决方案是-

因此将节点命令移至代码的另一部分——

 \draw[flecha] (g7_1) -- ++ (-0.2, 9) node[below right, pos=0.9] {1} -- ++ (-2.71, 0) -- (g5_10);

相关内容