3

This question already has an answer here:

I do not understand the presence of the red arrow in the table

\documentclass{standalone}
\usepackage{tikz}
\begin{document} 
\begin{tikzpicture}
\foreach \x/\xtext/\ytext in{0/x/y,1/1/4,2/1.5/6,3/2/8,4/5/20}
{\draw (\x,0.5) +(-0.5,-0.25) rectangle ++(0.5,0.25) ;
\draw (\x,0) +(-0.5,-0.25) rectangle ++(0.5,0.25);
\node[]  at (\x,0.5) {$\xtext$};
\node[]  at (\x,0)   {$\ytext$};
}
\draw[color=red,->,thick,>=stealth,shorten >=2pt,shorten <=2pt] (4.5,.65) edge [distance=1.2cm,bend left=80 ] node [right]{$\times 4$} (4.5,-.15);
\end{tikzpicture}
\end{document} 

enter image description here

marked as duplicate by Zarko tikz-pgf Sep 11 '17 at 1:19

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

5

An edge is a separate path which inherits, by default, all the attributes of its parent. Hence, an arrow tip is added to the main path and to the edge. However, you want it only for the edge. Hence, just don't add it to the main path.

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\begin{document} 
\begin{tikzpicture}
  \foreach \x/\xtext/\ytext in{0/x/y,1/1/4,2/1.5/6,3/2/8,4/5/20}
  {\draw (\x,0.5) +(-0.5,-0.25) rectangle ++(0.5,0.25) ;
    \draw (\x,0) +(-0.5,-0.25) rectangle ++(0.5,0.25);
    \node[]  at (\x,0.5) {$\xtext$};
    \node[]  at (\x,0)   {$\ytext$};
  }
  \draw[color=red,thick,>=Stealth,shorten >=2pt,shorten <=2pt] (4.5,.65) edge [distance=1.2cm,bend left=80, -> ] node [right]{$\times 4$} (4.5,-.15);
\end{tikzpicture}
\end{document} 

just the one arrow

Alternatively, you can avoid using an edge. Then you have just one path and TikZ will use just one arrow tip, as noted in balcinus's answer.

  • also can define every edge/.style={draw,-stealth} and than write edge [distance=1.2cm,bend left=80 ] node [right]{$\times 4$} (4.5,-.15); – Zarko Sep 10 '17 at 22:53
  • @Zarko True, but this has the look of a one-off arrow to me, given the context. But that would make sense in other cases. – cfr Sep 11 '17 at 0:08
  • @Zarko In truth, there is no reason for an edge here, after all ;). – cfr Sep 11 '17 at 0:10
6

I don't know why it is there either, but it disappears if you write (4.5,.65) to [distance=1.2cm,bend left=80 ] node [right]{$\times 4$} (4.5,-.15); instead of (4.5,.65) edge [distance=1.2cm,bend left=80 ] node [right]{$\times 4$} (4.5,-.15); (Notice to instead of edge)

\documentclass{standalone}
\usepackage{tikz}
\begin{document} 
\begin{tikzpicture}
   \foreach \x/\xtext/\ytext in{0/x/y,1/1/4,2/1.5/6,3/2/8,4/5/20}
      { 
        \draw (\x,0.5) +(-0.5,-0.25) rectangle ++(0.5,0.25) ;
        \draw (\x,0) +(-0.5,-0.25) rectangle ++(0.5,0.25);
        \node[]  at (\x,0.5) {$\xtext$};
        \node[]  at (\x,0)   {$\ytext$};
      }
      \draw[color=red,->,thick,>=stealth,shorten >=2pt,shorten <=2pt] (4.5,.65) to[distance=1.2cm,bend left=80 ] node [right]{$\times 4$} (4.5,-.15);
\end{tikzpicture}
\end{document} 
  • 2
    It is because to is part of the same path, whereas edge constructs a separate path with the same attributes. So you get two arrow tips with edge, if you specify -> for the parent path, but only one with to, which is just part of the same path. Alternatively, you can add the tip only to the edge (or override the arrow just for a particular edge, if that's needed in other cases). – cfr Sep 10 '17 at 21:18
  • Yes, but in this case the change was just too small and I thought a complete MWE would make it harder to spot the tiny change. – balcinus Sep 10 '17 at 21:25
  • Done. Hope it's better now. – balcinus Sep 10 '17 at 21:42
  • Yes, thank you for editing. If I could vote up again, I would, but the system won't let me :(. I've cleaned up my comments asking for the code you've supplied, though ;-). – cfr Sep 11 '17 at 0:09

Not the answer you're looking for? Browse other questions tagged or ask your own question.