5

In this MWE

\documentclass[border=5mm]{standalone}

\usepackage{tikz}
\usetikzlibrary{decorations.markings}

\begin{document}
\begin{tikzpicture}[path/.append style={
   decoration={
   markings,
     mark=at position 0.5 with {\arrow [scale=1.5]{stealth}},
   },
   postaction=decorate,
   thick,
 }]

   \draw[path] (-2, 0) -- (-0.5, 0);
   \draw[path] (-0.5, 0) arc [start angle=180, delta angle=-180, radius=0.5];
   \draw[path] (0.5, 0) -- (2, 0);
   \draw[path] (2, 0) arc [start angle=0, end angle=180, radius=2];
\end{tikzpicture}
\end{document}

The position of the arrows along the arc doesn't quite look right. Also, the arrows do not seem to be placed in the middle of the paths (wrong anchor).

How can I fix this?

  • If I had to guess, I would say that the horizontal center of the arrowhead is at the exact center of the path, but the arrowhead itself makes an optical illusion. – Matthew Leingang Nov 11 '14 at 16:41
  • 1
    @MatthewLeingang Actually, I believe the it's the tip of the arrow that is placed at the center. Some kind of time adjustment needs to be made, but right now I'm not sure how to do that. – A.Ellett Nov 11 '14 at 16:42
  • @A.Ellett right you are. I just compiled the MWE. – Matthew Leingang Nov 11 '14 at 16:43
6

It looks like you can add an option to \arrow to shift it.

\documentclass[border=5mm,png]{standalone}    
\usepackage{tikz}
\usetikzlibrary{decorations.markings}

\begin{document}
\begin{tikzpicture}[path/.append style={
   decoration={
       markings,
       mark=at position 0.5 with {\arrow[xshift=2.5\pgflinewidth,red,>=stealth]{>}}
   },
   postaction=decorate,
   thick,
 }]
   \draw[path] (-2, 0) -- (-0.5, 0);
   \draw[path] (-0.5, 0) arc [start angle=180, delta angle=-180, radius=0.5];
   \draw[path] (0.5, 0) -- (2, 0);
   \draw[path] (2, 0) arc [start angle=0, end angle=180, radius=2];
   \draw[help lines] (0,0) --++ (0,2) (1.25,0) --++ (0,2) (-1.25,0) --++ (0,02);
   \draw[help lines] (-2,0) --++ (4,0) (-2,0.5) --++ (4,0) (-2,2) --++ (4,0);
\end{tikzpicture}
\end{document}

sample code output

The magic number 2.5\pgflinewidth is half of the length of the stealth arrow tip, from point to the vertex of the cavity, as can be found by digging into pgfcorearrows.code.tex. This is about as good as I can do at the moment.

  • Idle observer's thought: if you could lower the arrowheads on the arches so that their tip touches the line of the arch, that would be absolutely perfect. Correct me if I am wrong! And I also think that ideally, the arrowhead should be centered to touch the line with its tip and vertex of the cavity. But otherwise a neat solution indeed! – ajeh Nov 11 '14 at 16:57
  • Nice job. I was curious about how to make this adjustment. – A.Ellett Nov 11 '14 at 17:25
  • 1
    This translates into a nice method for drawing tangent lines along the path by writing mark=at position 0.25 with {\path[draw,red,stealth-stealth] (-1cm,0) -- (1cm,0); } – A.Ellett Nov 11 '14 at 17:42

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.