6

I need to place mid-arrows on curved lines. The basic style works fine, but Latex and Stealth styles are not aligned properly. Is it possible to align arrow tip placement/direction with a curve? I also used a tikz block from TikZ: How to draw an arrow in the middle of the line? Below is my Latex code

\documentclass[12pt]{article} \usepackage[headings]{fullpage} \usepackage{tikz,tikz-cd} \usetikzlibrary{positioning} \usetikzlibrary{calc} \usetikzlibrary{decorations.pathreplacing} \usetikzlibrary{decorations.markings} \tikzset{ % style to apply some styles to each segment of a path on each segment/.style={ decorate, decoration={ show path construction, moveto code={}, lineto code={ \path [#1] (\tikzinputsegmentfirst) -- (\tikzinputsegmentlast); }, curveto code={ \path [#1] (\tikzinputsegmentfirst) .. controls (\tikzinputsegmentsupporta) and (\tikzinputsegmentsupportb) .. (\tikzinputsegmentlast); }, closepath code={ \path [#1] (\tikzinputsegmentfirst) -- (\tikzinputsegmentlast); }, }, }, % style to add an arrow in the middle of a path mid arrow/.style={postaction={decorate,decoration={ markings, mark=at position .5 with {\arrow[#1]{>}} }}}, mid stealth arrow/.style={postaction={decorate,decoration={ markings, mark=at position .5 with {\arrow[#1]{Stealth[]}} }}}, mid latex arrow/.style={postaction={decorate,decoration={ markings, mark=at position .5 with {\arrow[#1]{Latex[]}} }}} } \begin{document} $$ \begin{tikzpicture}[scale=1,baseline=20,x=5pt,y=5pt] \coordinate (t2) at (-5,-5); \coordinate (t3) at (0,6); \coordinate (t4) at (-4.5,-1); \coordinate (t5) at (-2.2,3.5); \path [draw,thick,postaction={on each segment={mid arrow}}] (t4) to[out=130,in=170] (t5) (t4) to [out=10, in=-60] (t5) (t2) to [out=90, in=-100] (t4) (t5) to [out=60, in=-135] (t3); \end{tikzpicture} \qquad,\qquad \begin{tikzpicture}[scale=1,baseline=20,x=5pt,y=5pt] \coordinate (t2) at (-5,-5); \coordinate (t3) at (0,6); \coordinate (t4) at (-4.5,-1); \coordinate (t5) at (-2.2,3.5); \path [draw,thick,postaction={on each segment={mid stealth arrow}}] (t4) to[out=130,in=170] (t5) (t4) to [out=10, in=-60] (t5) (t2) to [out=90, in=-100] (t4) (t5) to [out=60, in=-135] (t3); \end{tikzpicture} \qquad,\qquad \begin{tikzpicture}[scale=1,baseline=20,x=5pt,y=5pt] \coordinate (t2) at (-5,-5); \coordinate (t3) at (0,6); \coordinate (t4) at (-4.5,-1); \coordinate (t5) at (-2.2,3.5); \path [draw,thick,postaction={on each segment={mid latex arrow}}] (t4) to[out=130,in=170] (t5) (t4) to [out=10, in=-60] (t5) (t2) to [out=90, in=-100] (t4) (t5) to [out=60, in=-135] (t3); \end{tikzpicture} $$ \end{document} 

This code gives the output below. As you see, tips in the second and third picture are not aligned properly.

Arrow tips

2
  • Welcome to TeX.SX! You should provide the link to the source of your code. Maybe this can help as starting point: tex.stackexchange.com/q/222262/47927 (but look at the newer answers) Commented Jun 12 at 6:30
  • A good resource is already given by @JasperHabicht. Certainly, pascal974's answer will help a lot. One can use the \pgfarrowtotallength and the transformation also with \arrow in a marking decoration. I've also adapted a solution for bended arrow tips in my ext.arrows-plus library of my TikZ-Ext package. You should be able to just replace \arrow for \arrow* (only shifting) or \arrow** (also bending). Commented Jun 12 at 8:41

2 Answers 2

3

The arrows.meta library improves arrow styling, but correct alignment on curves or at small scales usually needs extra tweaking.

\documentclass[12pt]{article} \usepackage{tikz} \usetikzlibrary{decorations.markings} \usetikzlibrary{arrows.meta} \tikzset{ % A `mid arrow` style with a rotation angle parameter mid arrow/.style={ postaction={decorate}, decoration={ markings, mark=at position 0.5 with { \arrow[xshift=5pt, rotate=#1, ultra thick]{Stealth} } } } } \begin{document} \begin{tikzpicture}[scale=1] \coordinate (t2) at (-5,-5); \coordinate (t3) at (0,6); \coordinate (t4) at (-4.5,-1); \coordinate (t5) at (-2.2,3.5); \path[draw, thick, mid arrow=2] (t4) to[out=130,in=170] (t5); \path[draw, thick, mid arrow=-2] (t4) to[out=10,in=-60] (t5); \path[draw, thick, mid arrow=0] (t2) to[out=90,in=-100] (t4); \path[draw, thick, mid arrow=2] (t5) to[out=60,in=-135] (t3); \end{tikzpicture} % \begin{tikzpicture}[scale=0.5] \coordinate (t2) at (-5,-5); \coordinate (t3) at (0,6); \coordinate (t4) at (-4.5,-1); \coordinate (t5) at (-2.2,3.5); \path[draw, thick, mid arrow=2] (t4) to[out=130,in=170] (t5); \path[draw, thick, mid arrow=-2] (t4) to[out=10,in=-60] (t5); \path[draw, thick, mid arrow=0] (t2) to[out=90,in=-100] (t4); \path[draw, thick, mid arrow=2] (t5) to[out=60,in=-135] (t3); \end{tikzpicture} % \begin{tikzpicture}[scale=0.25] \coordinate (t2) at (-5,-5); \coordinate (t3) at (0,6); \coordinate (t4) at (-4.5,-1); \coordinate (t5) at (-2.2,3.5); \path[draw, thick, mid arrow=2] (t4) to[out=130,in=170] (t5); \path[draw, thick, mid arrow=-2] (t4) to[out=10,in=-60] (t5); \path[draw, thick, mid arrow=0] (t2) to[out=90,in=-100] (t4); \path[draw, thick, mid arrow=2] (t5) to[out=60,in=-135] (t3); \end{tikzpicture} \end{document} 

enter image description here

2
  • OP is already using the arrows.meta library (not package), it is loaded by tikz-cd. They are also using the markings decoration on paths created by the show path construction decoration. The latter is used to apply a common marking on all path segments (straight lines and curves). OP's arrows were also "symmetrically aligned". Use scale=.25 to see what OP's original problem is. Your document has the same problem, it is just not as noticeable. Commented Jun 12 at 8:34
  • @Qrrbrbirlbel Thank you for your comment. I’ll revise my answer accordingly. Let me just make sure I understand the issue correctly: when using scale=0.25, the arrow tips visually shift toward the beginning of the segment? In my code, this is exactly what happens. Commented Jun 12 at 9:58
3

For comparison, here is how that could be done in Metapost, which has nice curved arrows that follow the curvature of the path they are on.

curved arrows

You would need to compile the source with lualatex. Follow the link at the top for tutorials and reference material.

\documentclass[border=5mm]{standalone} \usepackage{luamplib} \begin{document} \mplibtextextlabel{enable} \begin{mplibcode} input colorbrewer-rgb beginfig(1); z2 = ( -5, -5) scaled 3mm; z3 = ( 0, 6) scaled 3mm; z4 = (-4.5, -1) scaled 3mm; z5 = (-2.2, 3.5) scaled 3mm; path p[]; p1 = z2 {up} .. z4; p2 = z4 {dir 120} .. z5; p3 = z4 {dir 10} .. z5; p4 = z5 {dir 60} .. z3; picture A[]; A1 = image( forsuffixes @ = 1,2,3,4: drawarrow subpath (0, .53) of p@; draw subpath (.47,1) of p@; endfor ); input mparrows setarrows(barbed); barbedarrowindent := 0.5; A2 = image( forsuffixes @ = 1,2,3,4: drawarrow subpath (0, .53) of p@; draw subpath (.47,1) of p@; endfor ); input cmarrows setup_cmarrows(macro_name="drawarrow"; arrow_name="texarrow";parameter_file = "cmr10.mf"); A3 = image( forsuffixes @ = 1,2,3,4: drawarrow subpath (0, .53) of p@; draw subpath (.47,1) of p@; endfor ); for i = 1,2,3: draw A[i] shifted (60i,0); endfor endfig; \end{mplibcode} \end{document} 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.