8

I'm trying to position a square node midway along a curved path, but I've noticed that the arrowhead style I select affects the positioning -- if I use an arrowhead other than the default, the node is positioned 'off center' in the normal direction to the path. Is there a different way to specify this to have the node correctly centered with e.g. the 'latex' style arrowheads?

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
  \draw[<->,bend angle=90,thick] (-1,-1)
  to[bend right] 
  node[rectangle,sloped,fill=black,minimum size=1mm,inner sep=0pt] {}
  (1,0);
  \begin{scope}[shift={(2,0)}]
    \draw[<->,>=stealth,bend angle=90,thick] (-1,-1) to[bend right] 
    node[rectangle,sloped,fill=black,minimum size=1mm,inner sep=0pt] {}
    (1,0);
  \end{scope}
  \begin{scope}[shift={(4,0)}]
    \draw[<->,>=latex,bend angle=90,thick] (-1,-1) to[bend right] 
    node[rectangle,sloped,fill=black,minimum size=1mm,inner sep=0pt] {}
    (1,0);
  \end{scope}
\end{tikzpicture}
\end{document}

enter image description here

3
  • It's not that the arrows are moving the node, but rather the different arrow types are redefining the path.
    – A.Ellett
    Commented Dec 23, 2015 at 6:31
  • 1
    And, the node position appears to be calculated upon the path without arrows.
    – A.Ellett
    Commented Dec 23, 2015 at 6:34
  • Arrowheads normally shorten a line by the length of the arrowhead, but that does not appear to be the case for curved lines. Commented Dec 23, 2015 at 15:53

1 Answer 1

6

This can be solved by using the TikZ bending library.

\documentclass[border=10pt]{standalone}

\usepackage{tikz}
\usetikzlibrary{bending}

\tikzset{%
  my node/.style={rectangle,sloped,fill=black,minimum size=1mm,inner sep=0pt},
  draw my path/.style={draw,bend angle=90,thick,#1},
}

\begin{document}

\begin{tikzpicture}
  \draw[draw my path={<->}] (-1,-1) to[bend right] node[my node] {} (1,0);

  \begin{scope}[shift={(2,0)}]
    \path[draw my path={<->,>=stealth}] (-1,-1) to[bend right] node[my node] {} (1,0);
  \end{scope}

  \begin{scope}[shift={(4,0)}]
    \path[draw my path={<->,>=latex}] (-1,-1) to[bend right] node[my node] {} (1,0);
  \end{scope}

\end{tikzpicture}

\end{document}

enter image description here

It appears that the path used to calculate the node positions and the path used when drawing and adding arrows are different. I've hobbled together the following to show the difference: red being the color of the path for the node.

enter image description here

Code:

\documentclass[border=10pt]{standalone}

\usepackage{tikz}
%\usetikzlibrary{bending}

\tikzset{%
  my node/.style={rectangle,sloped,fill=black,minimum size=1mm,inner sep=0pt,#1},
  draw my path/.style={draw,bend angle=90,thick,#1},
}

\begin{document}

\begin{tikzpicture}
  \draw[draw my path={<->}] (-1,-1) to[bend right] node[my node] {} (1,0);

  \begin{scope}[shift={(2,0)}]
    \path[orange,draw my path,thin]  (-1,-1) to[bend right] node[my node] {} (1,0);
    \path[draw my path={<->,>=stealth}] (-1,-1) to[bend right] node[my node] {} (1,0);
  \end{scope}

  \begin{scope}[shift={(4,0)}]
    \path[orange,draw my path,thin]  (-1,-1) to[bend right] node[my node] {} (1,0);
    \path[draw my path={<->,>=latex}] (-1,-1) to[bend right] node[my node] {} (1,0);
  \end{scope}

\end{tikzpicture}

\end{document}
1
  • Great, that's a simple fix and solves the problem. I'd still be interested if there is a way to access the original arrow path, though, as the arrows look a bit better without the 'bending' library IMO. Commented Dec 24, 2015 at 5:00

You must log in to answer this question.

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