Tikz:避免图形中的两个圆弧合并为一个双向箭头

Tikz:避免图形中的两个圆弧合并为一个双向箭头

我想绘制一个有向图 G(V,A),其中包含有向弧。问题是,如果我绘制 2 个弧,一个从 a 到 b,另一个从 b 到 a,这 2 个弧会合并为一个双向箭头(不确定这是否是正确的词)

以下是一些代码:

\documentclass{beamer}
\usepackage{tikz}
\usepackage{verbatim}
\usetikzlibrary{arrows,shapes}

\begin{document}
\tikzstyle{vertex}=[circle,fill=black!25,minimum size=20pt,inner sep=0pt]
\tikzstyle{edge} = [draw,thick,->]
\tikzstyle{weight} = [font=\small]
\begin{figure}
\begin{tikzpicture}[scale=1.8, auto,swap]
% draw the vertices
\foreach \pos/\name in {{(0,2)/a}, {(3,2)/b}}
    \node[vertex] (\name) at \pos {$\name$};
% Connect vertices with edges and draw weights
\foreach \source/ \dest /\weight in {a/b/1, b/a/2}
    \path[edge] (\source) -- node[weight] {$\weight$} (\dest);
\end{tikzpicture}
\end{figure}
\end{document}

结果如下:

错误的

它应该是两个独立的弧(一个从 a 到 b,一个从 b 到 a)。

答案1

--画一条直线,如果改用to[bend right],则会得到两个弯曲的箭头。

在此处输入图片描述

\documentclass{beamer}
\usepackage{tikz}
\usepackage{verbatim}
\usetikzlibrary{arrows,shapes}

\begin{document}
\tikzstyle{vertex}=[circle,fill=black!25,minimum size=20pt,inner sep=0pt]
\tikzstyle{edge} = [draw,thick,->]
\tikzstyle{weight} = [font=\small]
\begin{figure}
\begin{tikzpicture}[scale=1.8, auto,swap]
% draw the vertices
\foreach \pos/\name in {{(0,2)/a}, {(3,2)/b}}
    \node[vertex] (\name) at \pos {$\name$};
% Connect vertices with edges and draw weights
\foreach \source/ \dest /\weight in {a/b/1, b/a/2}
    \path[edge] (\source) to[bend right] node[weight] {$\weight$} (\dest);
\end{tikzpicture}
\end{figure}
\end{document}

相关内容