[Tex/LaTex] Strange arrow mark with TikZ edge and anchors.

tikz-pgf

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?

Best Answer

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}