2

Why is the left arrowhead wrong, and how can I fix it?

\documentclass[border=5pt]{standalone}

\usepackage{tikz}

\begin{document}
    \begin{tikzpicture}[auto]
    \draw[<->] (0,0) edge node {$a$} (1,0);
    \end{tikzpicture}
\end{document}  

enter image description here

It works fine if there is no edge node:

...
\draw[<->] (0,0) -- (1,0);
...

enter image description here

5
  • 1
    Try \draw (0,0) edge[<->] (1,0); . Or use tips=proper or tips=on proper draw, see tex.stackexchange.com/a/469851/194703.
    – user194703
    Commented Sep 28, 2019 at 0:58
  • The first idea doesn't help because I lose the edge label. But tips=proper works. What's the idea here? Commented Sep 28, 2019 at 1:00
  • Also, if you write this as an answer I'll accept. Commented Sep 28, 2019 at 1:00
  • Thanks for the offer. However, I feel the credits should go to Paul Gaborit for tex.stackexchange.com/questions/468866/…. If you want, I could add a (community wiki) answer when I am back at my laptop.
    – user194703
    Commented Sep 28, 2019 at 1:04
  • Up to you. My opinion is that your answer is a valid answer to my question and a non-trivial adaptation of Paul Gaborit's comment on that thread, and you deserve credit for the answer. But however you like. Commented Sep 28, 2019 at 1:11

2 Answers 2

1

Here are a few ways to resolve this. The issue is that an edge creates an independent path. As originally pointed out by Paul Gaborit, one may use the keys tip=proper or tips=on proper draw, which are described in pgfmanual v3.1.4b on p. 188. IMHO the cleaner solution is to pass the arrow heads to the edge. The arguably cleanest way is to replace edge by to, which avoids drawing two separate paths. There are further option such as using \path instead of draw, but IMHO this defeats the purpose because the path is still there and may (at least in principle) alter the bounding box, say.

\documentclass[border=5pt]{standalone}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}[auto,font=\sffamily]
 \begin{scope}[local bounding box=original]
    \draw[<->] (0,0) edge node {$a$} (1,0); 
 \end{scope}    
 \node[above] at (original.north) {original situation};
 %
 \begin{scope}[xshift=4cm,local bounding box=proper,tips=proper]
    \draw[<->] (0,0) edge node {$a$} (1,0); 
 \end{scope}    
 \node[above] at (proper.north) {\texttt{tips=proper}};
 %
 \begin{scope}[yshift=-2cm,local bounding box=on proper draw,tips=on proper draw]
    \draw[<->] (0,0) edge node {$a$} (1,0); 
 \end{scope}    
 \node[above] at (on proper draw.north) {\texttt{tips=on proper draw}};
 %
 \begin{scope}[yshift=-2cm,xshift=4cm,local bounding box=clean]
    \draw (0,0) edge[<->] node {$a$} (1,0); 
 \end{scope}    
 \node[above] at (clean.north) {cleaner(?) solution};
 %
 \begin{scope}[yshift=-4cm,local bounding box=to]
    \draw[<->] (0,0) to node {$a$} (1,0); 
 \end{scope}    
 \node[above] at (to.north) {\texttt{to} instead of \texttt{edge}};
 %
 \begin{scope}[yshift=-4cm,xshift=4cm,local bounding box=path]
    \path[<->] (0,0) edge node {$a$} (1,0); 
 \end{scope}    
 \node[above] at (path.north) {\texttt{\textbackslash path} instead of
 \texttt{\textbackslash draw}};
\end{tikzpicture}
\end{document}  

enter image description here

3
  • So, is the issue here that \draw[<->] (0,0) edge node {$a$} (1,0); first draws a zero-length edge from (0,0) to itself, then another edge to (1,0), so there's a sort of extra arrowhead? If so, why? Commented Sep 28, 2019 at 2:21
  • @LarrySnyder610 Because you start a path at (0,0) and then add another one with edge. If you use to instead of edge, the issue does not arise.
    – user194703
    Commented Sep 28, 2019 at 2:28
  • 1
    I see. I didn’t realize edge creates a new path. Thanks. Commented Sep 28, 2019 at 2:30
1

One way is to define edge:

\documentclass[border=5pt]{standalone}
\usepackage{tikz}

\begin{document}
    \begin{tikzpicture}[auto,
every edge/.style={draw, <->}
                ]
    \draw (0,0) edge node {$a$} (1,0);
    \end{tikzpicture}
\end{document}  

which gives:

enter image description here

or use the quotes library:

\documentclass[border=5pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{quotes}

\begin{document}
    \begin{tikzpicture}[auto,
every edge/.style={draw, <->}
                ]
    \draw (0,0) edge[<->, "$a$"] (1,0);
    \end{tikzpicture}
\end{document}  

or combination of both suggestions.

You must log in to answer this question.

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