如何绘制有向图?

如何绘制有向图?

我需要绘制下图:

有向图 我已经编写了以下代码:此代码未生成图形的方向。如何执行此操作并根据我附上的图进行组织?

\documentclass[border=1cm]{standalone}
\usepackage{tikz}

\begin{document}
    \begin{tikzpicture}
        %% vertices
        \draw[fill=black] (0,0) circle (3pt);
        \draw[fill=black] (4,0) circle (3pt);
        \draw[fill=black] (2,-1) circle (3pt);
        \draw[fill=black] (4,2) circle (3pt);
        \draw[fill=black] (0,2) circle (3pt);
        
        % labelleds
        \node at (-0.5,2) {$a$};
        \node at (-0.5,0) {$b$};
        \node at (4.5,0) {$c$};
        \node at (2.5,-1.2) {$e$};
        \node at (4,2.3) {$d$};
        %% arcs
        \draw[->]
        (2,-1) -- (0,0) -- (4,2) -- (4,0);
        \draw[->] (2,-1) -- (4,0);
        \draw[->] (0,0) -- (4,0);
        \draw[->] (0,2) -- (0,0);
    \end{tikzpicture}
\end{document}

在此处输入图片描述

答案1

另一种可能性:

  • dot对于节点,使用标签选项定义样式
  • 使用的是绝对坐标(对 OP MWE 稍作修改)
  • foredge是定义样式,它有选项postaction=decorate
\documentclass[border=3.141592]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
                decorations.markings}

\begin{document}
    \begin{tikzpicture}[
       decoration = {markings,
                     mark=at position .5 with {\arrow{Stealth[length=2mm]}}},
       dot/.style = {circle, fill, inner sep=2.4pt, node contents={},
                     label=#1},
every edge/.style = {draw, postaction=decorate}
                        ]
\node (a) at (0,5) [dot=$a$];
\node (b) at (1,2) [dot=below:$b$];
\node (c) at (4,2) [dot=$c$];
\node (d) at (6,4) [dot=right:$d$];
\node (e) at (3,0) [dot=right:$e$];
%
\path   (a) edge (b)    (b) edge (c)    
        (c) edge (d)    (c) edge (e)
        (d) edge[bend left] (c);
    \end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

这是一种方法。

在此处输入图片描述

\documentclass[tikz,border=5mm]{standalone}
\usetikzlibrary{decorations.markings}
\begin{document}
\begin{tikzpicture}
\tikzset{myarrow/.style={postaction={decorate},
decoration={markings,% switch on markings
mark=at position #1 with {\arrow{latex}},
}}}
    
\path
(0,0) coordinate (a) node[above]{$a$}--     
++(-60:1.5) coordinate (b) node[below left]{$b$}--
++(0:2.5) coordinate (c) node[above]{$c$}--
+(30:2) coordinate (d) node[right]{$d$}--
+(-130:2) coordinate (e) node[below]{$e$}
;
\draw[myarrow=.5] (a)--(b);
\draw[myarrow=.5] (b)--(c);
\draw[myarrow=.5] (c)--(d);
\draw[myarrow=.5] (e)--(c);
\draw[myarrow=.5] (d) to[bend left=40] (c);

\foreach \p in {a,...,e}
\fill (\p) circle(1.5pt);
\end{tikzpicture}
\end{document}

相关内容