如何添加源自 tikz 节点的弯曲箭头

如何添加源自 tikz 节点的弯曲箭头

我是 tikz 绘图的新手,现在我遇到的问题是我不知道如何绘制源自 tikz 节点的弯曲箭头,以及如何更改节点的 tex 大小。以下是我的代码。非常感谢您的帮助。

\documentclass[tikz]{standalone}
 \usetikzlibrary{positioning}
 \tikzset{state/.style={circle,draw=black}}
    \begin{document}

        \begin{tikzpicture}[transform shape, scale = 0.55, very thin ,node distance=0.7cm, text centered, text width = 0.85em]
        [dotnode/.style={dotted, draw=black, line width=0.1pt}]
        %\tikzstyle{every state}=[fill=none,text=black]
        \node[state] (1)[inner sep=0pt,minimum size=1pt]  {\tiny 1};
        \node[state] (2)  [above=of 1,inner sep=0pt,minimum size=1pt] {\tiny 2};
        \node[state] (3)  [above=of 2,inner sep=0pt,minimum size=1pt] {\tiny 4};
        \node[state] (4)  [above=of 3,inner sep=0pt,minimum size=1pt]{\tiny 8};
        \node[state] (5)  [above=of 4,inner sep=0pt,minimum size=1pt]{\tiny 16};
        \node[state] (6)  [above=of 5,inner sep=0pt,minimum size=1pt] {\tiny 17};
        \node[state] (7)  [above=of 6,inner sep=0pt,minimum size=1pt] {\tiny 18};
        \node[state] (8)  [above=of 7,inner sep=0pt,minimum size=1pt] {\tiny  W};

         \node[state] (9)  [right=of 1,inner sep=0pt,minimum size=1pt]{\tiny 1};
        \node[state] (10)  [above=of 9,inner sep=0pt,minimum size=1pt] {\tiny 2};
        \node[state] (11)  [above=of 10,inner sep=0pt,minimum size=1pt] {\tiny 4};
        \node[state] (12)  [above=of 11,inner sep=0pt,minimum size=1pt]{\tiny 8};
        \node[state] (13)  [above=of 12,inner sep=0pt,minimum size=1pt]{\tiny 9};
        \node[state] (14)  [above=of 13,inner sep=0pt,minimum size=1pt] {\tiny 10};
        \node[state] (15)  [above=of 14,inner sep=0pt,minimum size=1pt] {\tiny  W};      

        \node[state] (16)  [right=of 9,inner sep=0pt,minimum size=1pt]{\tiny 1};
        \node[state] (17)  [above=of 16,inner sep=0pt,minimum size=1pt] {\tiny 2};
        \node[state] (18)  [above=of 17,inner sep=0pt,minimum size=1pt] {\tiny 4};
        \node[state] (19)  [above=of 18,inner sep=0pt,minimum size=1pt]{\tiny 5};
        \node[state] (20)  [above=of 19,inner sep=0pt,minimum size=1pt]{\tiny 6};
        \node[state] (21)  [above=of 20,inner sep=0pt,minimum size=1pt] {\tiny 7};
        \node[state] (22)  [above=of 21,inner sep=0pt,minimum size=1pt] {\tiny  W};  

        \node[state] (23)  [right=of 16,inner sep=0pt,minimum size=1pt]{\tiny 1};
        \node[state] (24)  [above=of 23,inner sep=0pt,minimum size=1pt] {\tiny 2};
        \node[state] (25)  [above=of 24,inner sep=0pt,minimum size=1pt] {\tiny 3};
        \node[state] (26)  [above=of 25,inner sep=0pt,minimum size=1pt]{\tiny 4};
        \node[state] (27)  [above=of 26,inner sep=0pt,minimum size=1pt]{\tiny 5};
        \node[state] (28)  [above=of 27,inner sep=0pt,minimum size=1pt] {\tiny 6};
        \node[state] (29)  [above=of 28,inner sep=0pt,minimum size=1pt] {\tiny  W}; 

      \node[state] (30)  [right=of 23,inner sep=0pt,minimum size=1pt]{\tiny 1};
        \node[state] (31)  [above=of 30,inner sep=0pt,minimum size=1pt]{\tiny 2};
        \node[state] (32)  [above=of 31,inner sep=0pt,minimum size=1pt] {\tiny 3};
        \node[state] (33)  [above=of 32,inner sep=0pt,minimum size=1pt] {\tiny  W/2}; 


        \draw[every loop, line width = 0.12mm]
        (1) edge[blue, dashed]  node {} (2)
        (2) edge[blue, dashed]  node {} (3)
        (3) edge[blue, dashed] node {} (4)
        (4) edge[violet] node {} (5)
        (5) edge[violet, dotted] node {} (6)
        (6) edge[violet, dotted] node {} (7)
        (7) edge[violet, dotted] node {} (8)

        (9) edge[blue, dashed]  node {} (10)
        (10) edge[blue, dashed]  node {} (11)
        (11) edge[blue, dashed] node {} (12)
        (12) edge[violet] node {} (13)
        (13) edge[violet, dotted] node {} (14)
        (14) edge[violet, dotted] node {} (15)

        (16) edge[blue, dashed]  node {} (17)
        (17) edge[blue, dashed]  node {} (18)
        (18) edge[blue, dashed] node {} (19)
        (19) edge[violet] node {} (20)
        (20) edge[violet, dotted] node {} (21)
        (21) edge[violet, dotted] node {} (22)

        (23) edge[blue, dashed]  node {} (24)
        (24) edge[blue, dashed]  node {} (25)
        (25) edge[blue, dashed] node {} (26)
        (26) edge[violet] node {} (27)
        (27) edge[violet, dotted] node {} (28)
        (28) edge[violet, dotted] node {} (29)


         (2) edge[bend right=335,blue, dashed]  node {} (9);   

\draw [->,green!30!black, dotted,scale=0.6] (7,12)--++(1,0) node [right,text=black] {A};
\draw [->,blue, dashed,scale=0.6] (7,11.5)--++(1,0) node [right,text=black] {B};
\draw [->,violet,scale=0.6] (7,11)--++(1,0) node [right,text=black] {C};
\draw [->,red, dash dot,scale=0.6] (7,10.5)--++(1,0) node [right,text=black] {D};
    \end{tikzpicture}
    \end{document}

在此处输入图片描述

答案1

我喜欢使用矩阵来放置节点,如下所示:

\documentclass[tikz]{standalone}
\usetikzlibrary{positioning}
\begin{document}
    \begin{tikzpicture}[font=\tiny,>=latex,]
    \tikzset{
        state/.style={circle,draw=black,minimum size=1em,inner sep=0pt},
            % mypic
            pics/mypic/.style={code={
                    \tikzset{mypic/.cd,#1}  
                    \def\pv##1{\pgfkeysvalueof{/tikz/mypic/##1}}%
                    \edef\m{\pv{m}}%
                    \edef\w{\pv{size}}%
                    \foreach \row [count=\j] in \m  {
                        \foreach \x [count=\i] in \row {
                            \node[state] (N-\j-\i)at
                            (\i*\w-\w,-\j*\w+\w)  {\x};
                        }%foreach
                    }%foreach
            }},mypic/.cd,m/.initial={{0}},size/.initial=1,/tikz/.cd,
            %
                    % mypic
            pics/myann/.style={code={
                    \draw [->,green!30!black, dotted,scale=0.6] (0,0) --++(1,0) node [right,text=black] {A};
                    \draw [->,blue, dashed,scale=0.6] (0,-0.5) --++(1,0) node [right,text=black] {B};
                    \draw [->,violet,scale=0.6] (0,-1) --++(1,0) node [right,text=black] {C};
                    \draw [->,red, dash dot,scale=0.6] (0,-1.5) --++(1,0) node [right,text=black] {D};
            }},myann/.cd,/tikz/.cd,
            %
    }
\def\clst{
    {w},
    {18,w,w,w},
    {17,10,7,6},
    {10, 9, 6, 5},
    {8,  8,  5,  4,  w/2},
    {4,  4,  4,  3,  3},
    {2,  2,  2,  2,  2},
    {1,  1,  1,  1,  1}%
}
  \matrix (M) {
    \pic{mypic={m=\clst,size=1cm}};\\
  };
  \foreach \j in {1,...,4} {
    \foreach \i [evaluate=\i as \k using int(\i-1)] in {8,7,...,3} {
        \ifnum\i<5
            \tikzset{linestyle/.style={violet,dotted}}
        \else
        \ifnum\i=5
            \tikzset{linestyle/.style={violet}}
            \else
                \tikzset{linestyle/.style={blue,dashed}}
            \fi
        \fi
            \draw[every loop, line width = 0.12mm] 
            (N-\i-\j) edge[linestyle]  node {} (N-\k-\j);
    }
  }
\draw[every loop, line width = 0.12mm] 
(N-2-1) edge[violet, dashed]  node {} (N-1-1);

\foreach \i in {1,2,...,8}  {
    \draw[->] (N-\i-1.east) to[bend left] ++ (-45:0.5);
}

\matrix[right=0 of N-2-4.north east,anchor=south west] (N) {
    \pic{myann};\\
};
    \end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容