Tikz 循环大小不同(使其相同!)

Tikz 循环大小不同(使其相同!)
\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{arrows.meta,
                calc, chains, 
                positioning}
         \begin{document}       
                \begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=4cm,
                thick,main node/.style={circle,draw,font=\Large\bfseries,
    align=center,
    execute at begin node=\setlength{\baselineskip}{2em}}]

  \node[main node] (1) {1 \\ s};
  \node[main node] (2) [below left of=1] {2};
  \node[main node] (3) [below right of=1] {3};

  \path
    (1) edge [loop above] node {0.6} (1)
        edge [bend right] node {0.4} (2)
    (2) edge node [below]{1.0} (1)
    (3) edge [loop below] node {0.8} (3)
        edge node[right] {0.1} (1)
        edge node[below] {0.1} (2);      
\end{tikzpicture}
\end{document}

我看到节点 1\\s 上的循环比其他循环大,但我怎样才能使它与较小的循环大小相同?

在此处输入图片描述

答案1

环的大小会根据其所连接的节点的大小进行调整。恕我直言,如果所有节点的大小相同,那么从审美上来说会更令人愉悦。

\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{arrows.meta,calc,positioning}
\begin{document}       
\begin{tikzpicture}[->,>=Stealth,shorten >=1pt,auto,node distance=4cm,
    thick,main node/.style={circle,draw,font=\Large\bfseries,
    align=center,
    execute at begin node=\setlength{\baselineskip}{2em},
    },auto]

  \path node[main node] (1) {1 \\ s}
   let \p1=($(1.north)-(1.south)$) in
   node[main node,minimum size=\y1] (2) [below left=of 1] {2}
   node[main node,minimum size=\y1] (3) [below right=of 1] {3};

  \path
    (1) edge [loop above] node {0.6} (1)
        edge [bend right] node {0.4} (2)
    (2) edge node [below right]{1.0} (1)
    (3) edge [loop below] node {0.8} (3)
        edge node[above right] {0.1} (1)
        edge node[below] {0.1} (2);      
\end{tikzpicture}
\end{document}

在此处输入图片描述

您也可以只增加looseness

\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{arrows.meta,calc,positioning}
\begin{document}       
\begin{tikzpicture}[->,>=Stealth,shorten >=1pt,auto,node distance=4cm,
    thick,main node/.style={circle,draw,font=\Large\bfseries,
    align=center,
    execute at begin node=\setlength{\baselineskip}{2em},
    },auto]

  \path node[main node] (1) {1 \\ s}
   node[main node] (2) [below left=of 1] {2}
   node[main node] (3) [below right=of 1] {3};

  \path
    (1) edge [loop above] node {0.6} (1)
        edge [bend right] node {0.4} (2)
    (2) edge node [below right]{1.0} (1)
    (3) edge [loop below,looseness=22] node {0.8} (3)
        edge node[above right] {0.1} (1)
        edge node[below] {0.1} (2);      
\end{tikzpicture}
\end{document}

在此处输入图片描述

或者减少较大环的松弛度。

\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{arrows.meta,calc,positioning}
\begin{document}       
\begin{tikzpicture}[->,>=Stealth,shorten >=1pt,auto,node distance=4cm,
    thick,main node/.style={circle,draw,font=\Large\bfseries,
    align=center,
    execute at begin node=\setlength{\baselineskip}{2em},
    },auto]

  \path node[main node] (1) {1 \\ s}
   node[main node] (2) [below left=of 1] {2}
   node[main node] (3) [below right=of 1] {3};

  \path
    (1) edge [loop above,looseness=3] node {0.6} (1)
        edge [bend right] node {0.4} (2)
    (2) edge node [below right]{1.0} (1)
    (3) edge [loop below] node {0.8} (3)
        edge node[above right] {0.1} (1)
        edge node[below] {0.1} (2);      
\end{tikzpicture}
\end{document}

在此处输入图片描述

为了使循环相同,使用

\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{arrows.meta,calc,positioning}
\begin{document}       
\begin{tikzpicture}[->,>=Stealth,shorten >=1pt,auto,node distance=4cm,
    thick,main node/.style={circle,draw,font=\Large\bfseries,
    align=center,
    execute at begin node=\setlength{\baselineskip}{2em},
    },auto,]

  \path node[main node] (1) {1 \\ s}
   node[main node] (2) [below left=of 1] {2}
   node[main node] (3) [below right=of 1] {3};

  \path
    ([xshift=-1ex]1.north) edge [out=110,in=70,looseness=5] node {0.6}
    ([xshift=1ex]1.north)
    (1)   edge [bend right] node {0.4} (2)
    (2) edge node [below right]{1.0} (1)
    ([xshift=-1ex]3.south) edge [out=-110,in=-70,looseness=5] node[below] {0.8}
    ([xshift=1ex]3.south) (3)
        edge node[above right] {0.1} (1)
        edge node[below] {0.1} (2);      
\end{tikzpicture}
\end{document}

在此处输入图片描述

人们可以将其作为一种风格,但是我在这里没有足够的空间和动力。

相关内容