1

The following code draws arrows at a mid point along the line:

\documentclass[tikz]{standalone}
\usetikzlibrary{decorations.markings}
\begin{document}
\begin{tikzpicture}[
        mid arrow/.style={
            postaction={decorate,decoration={
                markings,
                mark=at position .5 with {\arrow{latex}}
        }}
      },
    ]
    \draw[thin,gray,dashed] (0,-1) -- (0,1);
    \draw[mid arrow] (-1,0.1) -- (1,0.1);
    \draw[mid arrow] (1,-0.1) -- (-1,-0.1);
    \end{tikzpicture}
\end{document}

The result is as expected:

Arrows mid-way along lines

Note that the tip of the arrow is the point of reference for where the marking gets placed, which is why the dashed gray line intersects the two tips. (In general, this is what you want: an arrow at the end of the line should have its tip at the end of the line!)

However, I would like these two arrows to be "centered" on the mid-line, such as this:

Arrows properly centered on lines

(I achieved this by adjusting the position of the marking to 0.54, but of course this is a hack that depends on the length of the line.)

Is there some way either to anchor an arrow somewhere other than at its tip, or otherwise tweak the positioning of the mark by, say, 3.2pt (which, in my actual use case, is half the length of the arrow)?

1 Answer 1

2
\documentclass[tikz, border=1cm]{standalone}
\usetikzlibrary{decorations.markings, arrows.meta}
\begin{document}
\begin{tikzpicture}[
    mid arrow/.style={
        postaction={decorate,decoration={
            markings,
            mark=at position .5 with {\arrow{Latex[length=6.4pt, sep=-3.2pt -1]}}
    }}
  },
]
\draw[thin,gray,dashed] (0,-1) -- (0,1);
\draw[mid arrow] (-1,0.1) -- (1,0.1);
\draw[mid arrow] (1,-0.1) -- (-1,-0.1);
\draw[mid arrow, ultra thick] (-1,-0.4) -- (1,-0.4);
\draw[mid arrow, ultra thick] (1,-0.6) -- (-1,-0.6);
\end{tikzpicture}
\end{document}

Four arrow with tip at center line

Edit: The extra line width shift sep=-3.2pt -1 is wrong - this can be seen when making the arrow red

\documentclass[tikz, border=1cm]{standalone}
\usetikzlibrary{decorations.markings, arrows.meta}
\begin{document}
\begin{tikzpicture}[
    mid arrow/.style={
        postaction={decorate,decoration={
            markings,
            mark=at position .5 with {\arrow{Latex[length=6.4pt, sep=-3.2pt, red]}}
    }}
  },
]
\draw[thin,gray,dashed] (0,-1) -- (0,1);
\draw[thin,gray,dashed, xshift=3.2pt] (0,-1) -- (0,1);
\draw[thin,gray,dashed, xshift=-3.2pt] (0,-1) -- (0,1);
\draw[mid arrow] (-1,0.1) -- (1,0.1);
\draw[mid arrow] (1,-0.1) -- (-1,-0.1);
\draw[mid arrow, ultra thick] (-1,-0.4) -- (1,-0.4);
\draw[mid arrow, ultra thick] (1,-0.6) -- (-1,-0.6);
\end{tikzpicture}
\end{document}

Four lines with red arrow tips in the middle

Visually it looks wrong though when the arrows are black:

Four lines with arrow tips in the middle

I guess it will always be needed to do manual adjustments dependent on line width and arrow tip.

2
  • This is dark magic, I'm sure! Thanks so much!
    – rbrignall
    Jul 29 at 10:36
  • @rbrignall: See edit for correction Jul 29 at 11:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.