端の上にテキストを書くにはどうすればいいですか?

端の上にテキストを書くにはどうすればいいですか?

有向エッジを持つグラフを描画するための次のコードがあります。

\begin{tikzpicture}
% vertices
\node[vertex] (1) at  (0,0) {$\times$};
\node[below left=1cm of 1] (A) {};
\node[below right=1cm of 1] (B) {};
\node[vertex] (2) at  (2,0) {$+$};
\node[below left=1cm of 2] (C) {};
\node[below right=1cm of 2] (D) {};
\node[vertex] (3) at  (4,0) {$\times$};
\node[below left=1cm of 3] (E) {};
\node[below right=1cm of 3] (F) {};
\node[vertex] (4) at  (1,2) {$+$};
\node[vertex] (5) at  (3,2) {$\times$};
\node[vertex] (6) at  (2,4) {$+$};
\node[above=1cm of 6] (G) {};
%edges
\draw[edge] (1) to (4);
\draw[edge] (1) to (5);
\draw[edge] (2) to (4);
\draw[edge] (3) to (5);
\draw[edge] (4) to (6);
\draw[edge] (5) to (6);
\draw[edge] (A) to (1);
\draw[edge] (B) to (1);
\draw[edge] (C) to (2);
\draw[edge] (D) to (2);
\draw[edge] (E) to (3);
\draw[edge] (F) to (3);
\draw[edge] (6) to (G);
\end{tikzpicture}

これらのオプションで

\tikzset{vertex/.style = {shape=circle,draw,minimum size=1.5em}}
\tikzset{edge/.style = {->,> = latex'}}

これは次のグラフになる。

ここに画像の説明を入力してください

上、下、すべての端にテキストを追加する方法はありますか? さらに、ドキュメントの端ではなく、ドキュメントの中央にテキストを記述できますか?

答え1

ここに画像の説明を入力してください

\documentclass{standalone}
\usepackage{tikz}

\usetikzlibrary{calc,positioning,angles,arrows.meta,quotes,intersections}
\usetikzlibrary{through}

\begin{document}

\begin{tikzpicture}\tikzset{vertex/.style = {shape=circle,draw,minimum size=1.5em}}
\tikzset{edge/.style = {->}}
% vertices
\node[vertex] (1) at  (0,0) {$\times$};
\node[below left=1cm of 1] (A) {};
\node[below right=1cm of 1] (B) {};
\node[vertex] (2) at  (2,0) {$+$};
\node[below left=1cm of 2] (C) {};
\node[below right=1cm of 2] (D) {};
\node[vertex] (3) at  (4,0) {$\times$};
\node[below left=1cm of 3] (E) {};
\node[below right=1cm of 3] (F) {};
\node[vertex] (4) at  (1,2) {$+$};
\node[vertex] (5) at  (3,2) {$\times$};
\node[vertex] (6) at  (2,4) {$+$};
\node[above=1cm of 6] (G) {};
%edges
\draw[edge] (1) to node[left, sloped,xshift=4pt,yshift=4pt]{\tiny AA}(4);%<---instead of left can use right/ above/ below
\draw[edge] (1) to (5);
\draw[edge] (2) to (4);
\draw[edge] (3) to (5);
\draw[edge] (4) to (6);
\draw[edge] (5) to (6);
\draw[edge] (A) to (1);
\draw[edge] (B) to (1);
\draw[edge] (C) to (2);
\draw[edge] (D) to (2);
\draw[edge] (E) to (3);
\draw[edge] (F) to (3);
\draw[edge] (6) to (G);
\end{tikzpicture}
 \end{document}

関連情報