在tikz中更改边缘标签时出现小三角形

时间:2019-06-16 00:22:16

标签: latex tikz

我想创建一个有向图。我正在使用“ tikz”软件包。当我编译代码时,会创建一些大小为0的边。

通过将代码更改为\draw,边缘消失了。

Unwanted triangles

重现该问题的代码:

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{arrows,decorations.pathmorphing,backgrounds,positioning,fit,matrix,arrows.meta}

\begin{document}
\begin{tikzpicture}[>=stealth', shorten >=1pt,
    node distance=2cm, scale=1, font=\scriptsize,
    state/.style={circle, draw, minimum size=0.7cm}]

\node[state] (1) at (0,0) {$s$};
\node[state, above right of=1] (2) {$v_1$};
\node[state, below right of=1] (3) {$v_2$};
\node[state, right of=2] (4) {$v_3$};
\node[state, right of=3] (5) {$v_4$};
\node[state, below right of=4] (6) {$t$};

\path[draw, ->, red, thick] (1.60) edge node [above left] {12} (2.210);
\path[draw, <-] (1.30) edge node [below right] {4} (2.240);

\path[draw, ->] (2.15) edge node [above] {8} (4.165);
\path[draw, <-] (2.345) edge node [below] {4} (4.195);

\path[draw, ->, red, thick] (4.330) edge node [above right] {16} (6.120);
\path[draw, <-] (4.300) edge node [below left] {4} (6.150);

\path[draw, ->] (1.330) edge node [above right] {9} (3.120);
\path[draw, <-] (1.300) edge node [below left] {4} (3.150);

\path[draw, <-, red, thick] (3) edge node [right] {4} (2);

\path[draw, ->] (3.15) edge node [above] {10} (5.165);
\path[draw, <-] (3.345) edge node [below] {4} (5.195);

\path[draw, ->] (5) edge node [below right] {4} (6);
\path[draw, ->] (5) edge node [right] {7} (4);

\path[draw, ->] (4.240) edge node [below right] {5} (3.30);
\path[draw, <-, red, thick] (4.210) edge node [above left] {4} (3.60);

\end{tikzpicture}
\end{document}

1 个答案:

答案 0 :(得分:1)

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{arrows,decorations.pathmorphing,backgrounds,positioning,fit,matrix,arrows.meta}

\begin{document}
\begin{tikzpicture}[>=stealth', shorten >=1pt,
    node distance=2cm, scale=1, font=\scriptsize,
    state/.style={circle, draw, minimum size=0.7cm}]

\node[state] (1) at (0,0) {$s$};
\node[state, above right of=1] (2) {$v_1$};
\node[state, below right of=1] (3) {$v_2$};
\node[state, right of=2] (4) {$v_3$};
\node[state, right of=3] (5) {$v_4$};
\node[state, below right of=4] (6) {$t$};

\path (1.60) edge [->, red, thick] node [above left] {12} (2.210);
\path (1.30) edge [<-] node [below right] {4} (2.240);

\path (2.15) edge [->] node [above] {8} (4.165);
\path (2.345) edge [<-] node [below] {4} (4.195);

\path (4.330) edge [->, red, thick] node [above right] {16} (6.120);
\path (4.300) edge [<-] node [below left] {4} (6.150);

\path (1.330) edge [->] node [above right] {9} (3.120);
\path (1.300) edge [<-] node [below left] {4} (3.150);

\path (3) edge [<-, red, thick] node [right] {4} (2);

\path (3.15) edge [->] node [above] {10} (5.165);
\path (3.345) edge [<-] node [below] {4} (5.195);

\path (5) edge [->] node [below right] {4} (6);
\path (5) edge [->] node [right] {7} (4);

\path (4.240) edge [->] node [below right] {5} (3.30);
\path (4.210) edge  [<-, red, thick] node [above left] {4} (3.60);

\end{tikzpicture}
\end{document}

Direct Graph