
방향이 지정된 모서리를 사용하여 그래프를 그리는 다음 코드가 있습니다.
\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}