
我使用 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}