6

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?

3
  • 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. Commented Nov 11, 2014 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
    Commented Nov 11, 2014 at 16:42
  • @A.Ellett right you are. I just compiled the MWE. Commented Nov 11, 2014 at 16:43

1 Answer 1

7

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.

3
  • 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
    Commented Nov 11, 2014 at 16:57
  • Nice job. I was curious about how to make this adjustment.
    – A.Ellett
    Commented Nov 11, 2014 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
    Commented Nov 11, 2014 at 17:42

You must log in to answer this question.

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