29

When I draw an edge between two nodes with anchors and globally set option [->], I get an additional arrow tip symbol at the beginning of the last edge in the path. For example in

\documentclass{article}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
    \node (A) at (0,0) {$A$};
    \node (B) at (1,0) {$B$};

    \draw[->] (A.north east) edge (B.north west);

    \draw (A.south east) edge[->] (B.south west);
\end{tikzpicture}
\end{document}

the first \draw command produces incorrect output, while the second produces correct output:

result

Am I doing something wrong, or is this a bug in TikZ?

1
  • Nowadays, tips=proper or tips=on proper draw can be used so that PGF/TikZ will not draw that lonely arrow tip of that otherwise empty parent path. Though, using \path with edge is still the better solution to this problem – unless, of course, there is an actual path besides the edges. Commented Nov 22, 2022 at 11:40

2 Answers 2

38

This has to do with the fact that you are using \draw, while edge is usually used in conjunction with \path.

What happens when you use the edge operation is that TikZ first draws everything up to the edge keyword, and then starts a new path with the every edge style between the nodes/coordinates specified in your edge operation. So using edge essentially splits your \draw command in two:

\draw[->] (A.north east) edge (B.north west);

is the same as saying

\draw[->] (A.north east);
\path[every edge,->] (A.north east) -- (B.north west);

The first line will just create the arrowhead pointing up, while the second line creates the actual line with the arrow head.

Your example can be corrected like this:

\documentclass{article}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
    \node (A) at (0,0) {$A$};
    \node (B) at (1,0) {$B$};

    \path[->] (A.north east) edge (B.north west);

    \draw (A.south east) edge[->] (B.south west);
\end{tikzpicture}
\end{document}
1
  • Just ran into this. Thanks for the explanation. Commented Sep 8, 2011 at 20:58
1

Try to use to instead of edge like \draw[->] (A.north east) to (B.north west);. I had a similar situation and to worked for me.

3
  • 5
    In this simple case, this works without a doubt. But note that \draw[->] (a) to (b) to (c); and \path[->] (a) edge (b) edge (c); and \path[->] (a) edge (b) (b) edge (c); produce different outputs. Commented Jan 27, 2013 at 19:27
  • @Qrrbrbirlbel what will be the difference exactly? Commented Nov 29, 2022 at 10:39
  • The first will connect a to b and b to c where the second will connect a to b as well as a to c. The third creates the first with the edge syntax of the second by repeating the previous target as the new start of an edge but with two arrow tips than just one. I've talked about this a bit in another answer. Commented Nov 29, 2022 at 11:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .