# Arrow tip center with TikZ (and pgfplots)

The arrow default behaviour is shown on the left picture part. How can I achieve that the “circle” arrow tips (see the picture below) end at their center, as drawn in the right image, but without manual tweaking?

If it is important: I need it to mark beginning and end of a curve in pgfplots, but I missed this feature so many times in TikZ as well that I post the more general question.

\documentclass[tikz,border=5mm,convert]{standalone}

\usetikzlibrary{arrows}

\begin{document}

\begin{tikzpicture}
\draw [black!20] (-.2,-.2) grid (1.2,1.2);
\draw [<->] (0,0) -- (1,1);
\draw [o-*] (0,1) -- (1,0);
\begin{scope}[xshift=1.5cm]
\draw [black!20] (-.2,-.2) grid (1.2,1.2);
\draw [<->] (0,0) -- (1,1);
\draw [o-*] (-.06,1.06) -- (1.06,-.06);
\end{scope}
\end{tikzpicture}

\end{document}


Ignasi posted a solution that works with pgfplots as well (thanks for that) but it does not integrate in the arrows “system” and lengths have to be given manually. Is there a solution that provides these features?

Using the solution with pgfplots results in strange looking graphs if there are plot coordinates inside the arrow tip:

I consider this being a feature but a different behaviour could be beneficial. So, is there a possibility to automatically skip coordinates inside the arrow tip? Using a fill for the ring is no solution since it will remove other objects as well. Here the code for the plot:

\documentclass[tikz,convert]{standalone}

\usetikzlibrary{arrows.meta}
\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}[markstart/.style={{Circle[open, length=4mm]}-,shorten <=-2mm}]
\begin{axis}[width=5cm]
\addplot [markstart] coordinates { (0,0) (0.01,0) (0.01,0.01) (0.04,0.03) (.5,.5) };
\end{axis}
\end{tikzpicture}

\end{document}

• I'm not sure about what you want to obtain. Is it similar to \addplot [markstart] coordinates { (0,0) }; \addplot [no marks] coordinates { (0,0) (0.01,0) (0.01,0.01) (0.04,0.03) (.5,.5) };? – Ignasi Jul 21 '14 at 11:28
• No, more \addplot [markstart] coordinates { (0,0) (0.04,0.03) (.5,.5) };, i. e. automatically skipping of the coordinates inside of the ring. But that's just a bonus question, I added it mainly to show the picture as mentioned in the comment to your answer. The suggestion in your comment could as well be achieved by ... node [...,pos=0] {}, or am I wrong about that? – Chris Jul 21 '14 at 12:26
• I've updated my answer. Look if it helps. – Ignasi Jul 21 '14 at 14:25

If new (TiKZ 3.0) arrows.meta library is used, tip length can be fixed and with shorten help, arrows circle centers can be moved to point where you want:

\documentclass[tikz,border=5mm,convert]{standalone}

\usetikzlibrary{arrows.meta}

\begin{document}

\begin{tikzpicture}
\draw [black!20] (-.2,-.2) grid (1.2,1.2);
\draw [<->] (0,0) -- (1,1);
\draw [{Circle[open]}-{Circle}] (0,1) -- (1,0);
\begin{scope}[xshift=1.5cm]
\draw [black!20] (-.2,-.2) grid (1.2,1.2);
\draw [<->] (0,0) -- (1,1);
\draw [{Circle[open, length=1mm]}-{Circle[length=2mm]}, shorten >=-1mm, shorten <=-.5mm] (0,1) -- (1,0);
\end{scope}
\end{tikzpicture}

\end{document}


I supose there exists some variable which defines tip length and can be used to automatically compute shorten length, but I don't know it.

Update

If just want to mark start and ending point in a pgfplots curve, instead of tips and arrows can use pgfplots mark or just circle nodes as you said in your comments or is used in How to mark/label nth data point from file in pgfplots?

Unless you fill circle or marks internal lines will be shown (as in next figure). If you know how many coordinates are used to draw the curve, you can use mark repeat to draw a curve with marks just at start and end points.

\documentclass[tikz,border=5mm,convert]{standalone}

\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}[markstart/.style={{Circle[open, length=4mm] .}-,shorten <=-2mm}]
\begin{axis}[width=5cm]
\addplot [mark=none] coordinates { (0,0) (0.01,0) (0.01,0.01) (0.04,0.03) (.5,.5) } node[circle, minimum size=2pt,inner sep=0pt,draw,pos=0]{} node[circle, minimum size=2pt,inner sep=0pt,draw,pos=1]{};

\addplot [mark=o, mark repeat=4] coordinates { (0,0.4) (0.01,0.39) (0.01,0.35) (0.04,0.32) (.5,.0) };
\end{axis}
\end{tikzpicture}

\end{document}


• Thanks, that works even with pgfplots, albeit giving some strange looking results under special conditions (I will add an example picture to the question). Nevertheless, a solution with automatic computation would be handy, even better if it integrates into the arrows syntax. – Chris Jul 21 '14 at 9:07

While this does not exactly answer your question, it does provide a way of getting the circles (filled or not) where you want them without having to tweak things.

\documentclass[tikz,border=5mm,convert]{standalone}

\usetikzlibrary{arrows}

\begin{document}

\begin{tikzpicture}
\draw [black!20] (-.2,-.2) grid (1.2,1.2);

\node[circle,inner sep=1pt,draw] (A) at (0,1) {};
\node[circle,inner sep=1pt,draw,fill] (B) at (1,0) {};
\draw (A) -- (B);

\draw [<->] (0,0) -- (1,1);
\end{tikzpicture}

\end{document}


You can tidy this up a bit by defining styles for the end nodes and even defining a macro to accomplish this as in:

• Thanks for the suggestion, that's what I do for the simple cases, but it is e. g. not possible for pgfplots curves. – Chris Jul 21 '14 at 8:37