Tikz:如何正确显示一些链接节点?

Tikz:如何正确显示一些链接节点?

我已经使用 Tikz 创建了下图,有什么办法可以正确显示它吗?(因为它显示的所有节点都在最后一个节点下方,所以很混乱)

\documentclass{article}

\usepackage[spanish]{babel}

\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows}

\tikzstyle{io} = [ellipse, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=blue!30]
\tikzstyle{arrow} = [thick,->,>=stealth]

\begin{document}
\begin{tikzpicture}[node distance=2cm]
\node (1) [io] {1 1 1 1};
\node (2) [io, below of=1] {2 1 0 1};
\node (3) [io, below of=2] {1 0 1 2};
\node (4) [io, below of=3] {2 0 0 2};
\node (5) [io, below of=4] {0 0 2 2};
\node (6) [io, below of=5] {0 1 2 1};
\node (7) [io, below of=6] {0 2 2 0};
\node (8) [io, below of=7] {1 2 1 0};
\node (9) [io, below of=8] {2 2 0 0};

\draw [arrow] (1) -- node {t1} (2);
\draw [arrow] (2) -- node {t2} (3);
\draw [arrow] (3) -- node {t1} (4);
\draw [arrow] (4) -- node {t3} (2);
\draw [arrow] (3) -- node {t3} (1);
\draw [arrow] (2) -- node {t3} (9);
\draw [arrow] (9) -- node {t2} (1);
\draw [arrow] (1) -- node {t3} (8);
\draw [arrow] (1) -- node {t2} (5);
\draw [arrow] (5) -- node {t1} (3);
\draw [arrow] (5) -- node {t3} (6);
\draw [arrow] (6) -- node {t1} (1);
\draw [arrow] (6) -- node {t3} (7);
\draw [arrow] (7) -- node {t1} (8);
\draw [arrow] (8) -- node {t2} (6);
\draw [arrow] (8) -- node {t1} (9);

\end{tikzpicture}    
\end{document}

例如,如何以圆形布局显示节点?

答案1

您说的是“以圆形布局”。这是一个例子。您可以使用宏将节点放置在节点 (1) 周围at (<angle:distance>)

\documentclass{article}

\usepackage[spanish]{babel}

\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows}

\tikzstyle{io} = [ellipse, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=blue!30]
\tikzstyle{arrow} = [thick,->,>=stealth]

\begin{document}
\begin{tikzpicture}%[node distance=2cm]
\node (1) [io] {1 1 1 1};
\node (2) [io] at (45:2in) {2 1 0 1};
\node (4) [io] at (90:2in) {2 0 0 2};
\node (3) [io] at (135:2in) {1 0 1 2};
\node (5) [io] at (180:2in) {0 0 2 2};
\node (6) [io] at (225:2in) {0 1 2 1};
\node (7) [io] at (270:2in) {0 2 2 0};
\node (8) [io] at (315:2in) {1 2 1 0};
\node (9) [io] at (360:2in) {2 2 0 0};

\draw [arrow] (1) -- node[auto] {t1} (2);    %% note auto option here onwards
                                             %%        for proper placement.
\draw [arrow] (2) -- node[auto] {t2} (3);
\draw [arrow] (3) -- node[auto] {t1} (4);
\draw [arrow] (4) -- node[auto,xshift=1cm] {t3} (2);
\draw [arrow] (3) -- node[auto] {t3} (1);
\draw [arrow] (2) -- node[auto] {t3} (9);
\draw [arrow] (9) -- node[auto] {t2} (1);
\draw [arrow] (1) -- node[auto] {t3} (8);
\draw [arrow] (1) -- node[auto] {t2} (5);
\draw [arrow] (5) -- node[auto] {t1} (3);
\draw [arrow] (5) -- node[auto] {t3} (6);
\draw [arrow] (6) -- node[auto] {t1} (1);
\draw [arrow] (6) -- node[auto] {t3} (7);
\draw [arrow] (7) -- node[auto] {t1} (8);
\draw [arrow] (8) -- node[auto] {t2} (6);
\draw [arrow] (8) -- node[auto] {t1} (9);

\end{tikzpicture}
\end{document}

在此处输入图片描述

您可以自行调整拓扑以满足您的需要。

答案2

这里应该有一些可以帮助您开始使用语法并指定箭头的to锚点和in=角度的内容。out=

在此处输入图片描述

代码:

\documentclass{article}

\usepackage[spanish]{babel}

\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows}

\tikzstyle{io} = [ellipse, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=blue!30]
\tikzstyle{arrow} = [thick,->,>=stealth]

\begin{document}
\begin{tikzpicture}[node distance=2cm]
\node (1) [io] {1 1 1 1};
\node (2) [io, below of=1] {2 1 0 1};
\node (3) [io, below of=2] {1 0 1 2};
\node (4) [io, below of=3] {2 0 0 2};
%\node (5) [io, below of=4] {0 0 2 2};
%\node (6) [io, below of=5] {0 1 2 1};
%\node (7) [io, below of=6] {0 2 2 0};
%\node (8) [io, below of=7] {1 2 1 0};
%\node (9) [io, below of=8] {2 2 0 0};

\draw [arrow] (1.south) -- node[right] {t1} (2.north);
\draw [arrow] (2.south) -- node[right] {t2} (3.north);
\draw [arrow] (3.south) -- node[right] {t1} (4.north);
\draw [arrow,out=70,in=-70] (4.east) to node[right] {t3} (2.east);
\draw [arrow,out=170,in=-170] (3.west) to node[left] {t3} (1.west);
%\draw [arrow] (2.south) -- node[right] {t3} (9.north);
%\draw [arrow] (9.south) -- node[right] {t2} (1.north);
%\draw [arrow] (1.south) -- node[right] {t3} (8.north);
%\draw [arrow] (1.south) -- node[right] {t2} (5.north);
%\draw [arrow] (5.south) -- node[right] {t1} (3.north);
%\draw [arrow] (5.south) -- node[right] {t3} (6.north);
%\draw [arrow] (6.south) -- node[right] {t1} (1.north);
%\draw [arrow] (6.south) -- node[right] {t3} (7.north);
%\draw [arrow] (7.south) -- node[right] {t1} (8.north);
%\draw [arrow] (8.south) -- node[right] {t2} (6.north);
%\draw [arrow] (8.south) -- node[right] {t1} (9.north);

\end{tikzpicture}    
\end{document}

相关内容