如何使用 Tikz 创建 2 个箭头,而不是双头箭头

如何使用 Tikz 创建 2 个箭头,而不是双头箭头

我想在此图中节点 1&4 和节点 1&3 之间显示两个单独的箭头。我读到过关于弯曲箭头的文章,但我真的希望它们保持笔直。还看到有一个选项可以让它们以不同的角度离开节点,但我无法为此编写代码。有人能帮帮我吗!

这是我的代码

\begin{tikzpicture}
\tikzset{vertex/.style = {shape=circle,draw,minimum size=1.5em}}
\tikzset{edge/.style = {->,> = latex'}}
% vertices
\node[vertex] (1) at  (0,0) {$1$};
\node[vertex] (2) at  (2,0) {$2$};
\node[vertex] (3) at  (0,-2) {$3$};
\node[vertex] (4) at  (2,-2) {$4$};
%edges
\draw[edge] (1) to (2);
\draw[edge] (1) to (3);
\draw[edge] (1) to (4);
\draw[edge] (2) to (3);
\draw[edge] (2) to (4);
\draw[edge] (3) to (1);
\draw[edge] (4) to (3);
\draw[edge] (4) to (1);
\end{tikzpicture}

图形

我希望它看起来与此类似,有两个箭头而不是一个图2

答案1

您可以使用 访问位于特定角度的节点边缘上的点nodename.angle。请参阅下面我使用此功能的示例。

\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows}
\begin{document}
\begin{tikzpicture}
\tikzset{vertex/.style = {shape=circle,draw,minimum size=1.5em}}
\tikzset{edge/.style = {->,> = latex'}}
% vertices
\node[vertex] (1) at  (0,0) {$1$};
\node[vertex] (2) at  (2,0) {$2$};
\node[vertex] (3) at  (0,-2) {$3$};
\node[vertex] (4) at  (2,-2) {$4$};
%edges
\draw[edge] (1) to (2);
\draw[edge] (1.260) to (3.100);
\draw[edge] (1.325) to (4.125);
\draw[edge] (2) to (3);
\draw[edge] (2) to (4);
\draw[edge] (3.80) to (1.280);
\draw[edge] (4) to (3);
\draw[edge] (4.145) to (1.305);
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

您可以使用锚点参考文档第 67 节形状

\documentclass[border=1pt, tikz]{standalone}

\usetikzlibrary{positioning}

\begin{document}
\begin{tikzpicture}
  \tikzset{vertex/.style = {shape=circle,draw,minimum size=1.5em}}
  \tikzset{edge/.style = {->,> = latex}}
  % vertices
  \node[vertex] (1) at  (0,0) {$1$};
  \node[vertex] (2) at  (2,0) {$2$};
  \node[vertex] (3) at  (0,-2) {$3$};
  \node[vertex] (4) at  (2,-2) {$4$};
  % edges
  \draw[edge] (1.10) to (2.170);
  \draw[edge] (2.190) to (1.350);

  \draw[edge] (1) to (3);
  \draw[edge] (1.300) to (4.150);
  \draw[edge] (2) to (3);
  \draw[edge] (2) to (4);
  \draw[edge] (3) to (1);
  \draw[edge] (4) to (3);
  \draw[edge] (4.120) to (1.330);
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容