TransWikia.com

Midpoint arrows and shortening with the sep option

TeX - LaTeX Asked by hpekristiansen on April 2, 2021

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.

One Answer

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.

Answered by user232027 on April 2, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP