0

I have been experimenting with the TikZ sep arrow option, which allows to space arrows. I think that it can be hugely useful to also make midpoint arrows and to shorten paths. I have not yet seen anyone do this - maybe I have not looked closely enough.

Here I make some arrow distanced fist from one end and then the other end:

\documentclass[tikz, border=1cm]{standalone}
\usetikzlibrary {arrows.meta,bending}
\begin{document}
\begin{tikzpicture}
\newcommand{\mypath}{(0,0) to[out=90, in=-90] (4,2)}
\draw [red, -{>[sep=0.5cm] Butt Cap[]}] \mypath;
\draw [green, yshift=-1cm, {Butt Cap[] Stealth[reversed, sep=0.5cm]}-] \mypath;
\draw [blue, yshift=-2cm,
   {Butt Cap[] 
   Stealth[reversed, sep=0.1cm]
   Stealth[reversed, sep=0.2cm]
   Stealth[reversed, sep=0.4cm]
   Stealth[reversed, sep=0.8cm]
   Stealth[reversed, sep=1.6cm]
   }-] \mypath;
\end{tikzpicture}
\end{document}

Paths with positioned arrows

I do not like Butt Cap[] to avoid an arrow in the end. Are there some notation for no arrow. This: ->- does not work. Maybe a empty or \arrow[none] that I have overlooked in the manual? Is there any way to give relative length to sep? - sep=0.5 does not give a midpoint arrow (the unit is apparently pt).


Here I use the sep to shorten without changing the path. Normal shorten will shorten tangentially from the end point - see the green path:

\documentclass[tikz, border=1cm]{standalone}
\usetikzlibrary {arrows.meta,bending}
\begin{document}
\begin{tikzpicture}
\newcommand{\mypath}{(0,0) to[out=90, in=-90] (4,2)}
\draw [gray, thick] \mypath;
\draw [red, -{Butt Cap[sep=0.5cm]}] \mypath;
\draw [green, shorten >=0.5cm] \mypath;
\end{tikzpicture}
\end{document}

Zoom on shortened ends

Again, I do not like the Butt Cap arrow, as it overwrites(or are rather in addition to) the default line cap.

Edit: I am aware of many other midpoint arrow solutions e.g. here TikZ: How to draw an arrow in the middle of the line? , but none that uses sep.

1

1 Answer 1

1

This is not a complete answer, but an answer to one of the subquestions: you can define a shorthand, see p. 210 of pgfmanual 3.1.8.

\documentclass[tikz, border=1cm]{standalone}
\usetikzlibrary {arrows.meta,bending}
\begin{document}
\begin{tikzpicture}
\newcommand{\mypath}{(0,0) to[out=90, in=-90] (4,2)}
\draw [red, -{>[sep=0.5cm] Butt Cap[]}] \mypath;
\draw [green, yshift=-1cm, {Butt Cap[] Stealth[reversed, sep=0.5cm]}-] \mypath;
\draw [blue, yshift=-2cm,
   {Butt Cap[] 
   Stealth[reversed, sep=0.1cm]
   Stealth[reversed, sep=0.2cm]
   Stealth[reversed, sep=0.4cm]
   Stealth[reversed, sep=0.8cm]
   Stealth[reversed, sep=1.6cm]
   }-] \mypath;
\begin{scope}[xshift=6cm,b/.tip={Butt Cap[]}]
  \draw [red, -{>[sep=0.5cm]b}] \mypath;
  \draw [green, yshift=-1cm, {b Stealth[reversed, sep=0.5cm]}-] \mypath;
  \draw [blue, yshift=-2cm,
     {b 
     Stealth[reversed, sep=0.1cm]
     Stealth[reversed, sep=0.2cm]
     Stealth[reversed, sep=0.4cm]
     Stealth[reversed, sep=0.8cm]
     Stealth[reversed, sep=1.6cm]
     }-] \mypath;
\end{scope}
\end{tikzpicture}
\end{document}

enter image description here

As for the length of the path, one way to find it out is to use decorations.markings, but this may defeat the purpose.

4
  • 1
    @hpekristiansen \relax. The first half is the same to show that the output of the second half matches the original output. You wrote that you do not like to use Butt Cap[] and I explicitly told you that all I am doing here is to introduce a short cut. BTW, your suggestion to shift the arrow by a fraction of the path is conceptionally flawed, this can only work if you have one single stretch, e.g. a Bezier curve or a line, but not a full path that emerges from combining stretches.
    – user232027
    Commented Jan 3, 2021 at 22:40
  • @hpekristiansen If you are willing to use \usetikzlibrary{decorations.markings}, isn't your question moot? Then you just place the arrows wherever you want. Yes, there are tons of examples around, also in the manual, but I thought you wanted to try out something else. (BTW, you can select the right cap by playing with \csname pgfset#1cap\endcsname where #1 is either round, rect or butt. But given the language and exclamation marks used in the comments I am not in the mood to spell this out. \bye.)
    – user232027
    Commented Jan 3, 2021 at 22:49
  • @hpekristiansen If you read the pgf libraries that allow you to shift the arrow head you will see what I mean. Decorations reconstruct the complete path which is composed of segments whereas the arrows library accesses segments. Yes, conceptually flawed.
    – user232027
    Commented Jan 3, 2021 at 22:58
  • There is not much of a discussion. You charge into me for no reason, I wrote precisely what the post does. If this is not what you want, you can either make your question clearer or ignore the post, charging into others does not really help. Well, and if you cannot take "conceptually flawed", which is of course an unnecessarily strong expression that I would have avoided if this exchange had been civilized, then consider not charging into others who spend their time trying to answer your question.
    – user232027
    Commented Jan 4, 2021 at 0:46

You must log in to answer this question.

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