
TikZ で次のグラフを描くのを手伝ってくれる人はいませんか?
私は次のようなことから始めました:
\begin{tikzpicture}[ ->, >=Stealth, shorten >=1pt, auto, node distance=2cm, thick, main node/.style={circle,draw,font=\sffamily\Large\bfseries} ]
% Nodes
\node[main node] (b) at (0,0) {b};
\node[main node] (7) at (2,2) {7};
\node[main node] (4) at (2,0) {4};
\node[main node] (1) at (2,-2) {1};
\node[main node] (8) at (4,2) {8};
\node[main node] (5) at (4,0) {5};
\node[main node] (2) at (4,-2) {2};
\node[main node] (9) at (6,2) {9};
\node[main node] (6) at (6,0) {6};
\node[main node] (3) at (6,-2) {3};
\node[main node] (e) at (8,0) {e};
% Solid edges
\draw (b) -- (1);
\draw (b) -- (4);
\draw (b) -- (7);
\draw (1) -- (4);
\draw (2) -- (5);
\draw (3) -- (6);
\draw (4) -- (7);
\draw (5) -- (8);
\draw (6) -- (9);
\draw (7) -- (e);
\draw (8) -- (e);
\draw (9) -- (e);
% Dashed edges
\draw[dashed] (1) -- (8);
\draw[dashed] (8) -- (1);
\draw[dashed] (2) -- (3);
\draw[dashed] (4) -- (5);
\draw[dashed] (5) -- (6);
\draw[dashed] (7) -- (8);
\draw[dashed] (8) -- (9);
\end{tikzpicture}
しかし、利用可能なドキュメントに従って完成させるには非常に時間がかかります。ありがとうございます (画像で確認できる細い矢印は、コード スニペットで示されているように破線にすることができます)。
答え1
ここでは、ノードを配置し、2 つのループで値を使用して接続する手順を説明します。
このため、chains
ライブラリは、ノードを規則的に配置および接続するのに役立ちます。ノード間の距離は によって指定されますnode distance
。
ノード0
は、垂直方向に中央に配置されるように、ノード 1/3 と 1/4 の西側の中央の左側に配置されます。
graph
最後に、構文/ライブラリを介して既存のノード間にいくつかの簡単な接続を追加しました。
コード
\documentclass[tikz]{standalone}
\usetikzlibrary{arrows.meta, chains, calc, graphs, quotes, shapes.multipart}
\begin{document}
\begin{tikzpicture}[
node distance=1cm,
all nodes/.style={shape=circle, draw, minimum size=1cm},
node BF/.style 2 args={
all nodes, node other/.code=,shape=circle,
name=#1 #2,node contents=$#1_{#2}$},
node 7/.style={node BF={B}{#1}}, node 8/.style={node BF={F}{#1}},
node other/.style 2 args={
all nodes, shape=circle solidus, inner sep=.1em, name=#1 #2,
node contents={#2 \nodepart{lower} #1}},
>=Latex, every join/.style={->},
start chain=rows going below,
]
\foreach[count=\rowi] \rows in {{1, 3, 6, 7, 3, 6, -33},
{8, 5, 10, 10, 10, 4, -61},
{5, 4, 8, 9, 1, 7, -44},
{5, 5, 5, 3, 8, 9, -45},
{9, 3, 5, 4, 3, 1, -32},
{3, 3, 9, 10, 4, 1, -39}}{
\node[on chain, node other=\rowi 1];
\tikzset{start branch={row\rowi} going right}
\foreach[count=\coli from 2] \elem in \rows
\node[on chain, node \coli/.try=\rowi,
node other=\rowi\coli, join=by "$\elem$"];
}
\node[all nodes, left=2cm of $(3 1.west)!.5!(4 1.west)$](0){$0$}
foreach \rowi in {1, ..., 6}{
(0) edge[every join, "0" sloped] (\rowi\space 1)};
\path[dashed] graph[edges=every join, use existing nodes]{
1 1 ->[bend left] 3 1 ->[bend left] 5 1,
2 1 ->[bend right] 4 1 ->[bend right] 6 1
};
\foreach \up/\Row/\above/\rows in {+/1/above/{1,2,3}, -/6/below/{6,5,4}}
\foreach[count=\i from 0] \row in \rows
\draw[rounded corners, every join] (0)
|- node[at end, \above] {$0$} ([shift={(0,\up 1)}]B \Row.center)
to[out=0, in/.evaluated={\up(\i==0?135:60)}, out looseness={1+1.5*sign(\i)}](F \row);
\end{tikzpicture}
\end{document}