4

I want to bend my arrow such that it perfectly matches the circle. Right now, we see that the tip of the arrow is slightly above the border of the circle. I want to it lie on the centre line of the circle.

\documentclass{beamer}

\usetheme{metropolis}
\usepackage[fira]{fontsetup}

\usepackage{tikz}
\usetikzlibrary{shapes, decorations, arrows.meta, decorations.markings, bending}

\newcommand{\KP}[1]{%
    \begin{tikzpicture}[baseline=-\dimexpr\fontdimen22\textfont2\relax]
        #1
    \end{tikzpicture}%
}
\newcommand{\KPM}{%
    \KP{\filldraw[fill=none, thick, decoration={markings, mark=at position 0.27 with {\arrow{Straight Barb[length=2.15, reversed, bend]}}}, postaction={decorate}] circle (0.3);}%
}

\begin{document}
    \begin{frame}
        \KPM
    \end{frame}
\end{document}

circle with arrow

I have tried to copy the code from here: https://tex.stackexchange.com/a/7464/128462 and https://tex.stackexchange.com/a/306010/128462.

4 Answers 4

4

It seems that decorations.markings consider outer border of circle line (this may be consider as bug in decorations.markings library). This can be (partly) compensate by manually shift arrow closer to circle radius by use option yshift=-0.33\pgflinewidth:

\documentclass{beamer}
\usetheme{metropolis}

\usepackage[fira]{fontsetup}
\usepackage{tikz}
\usetikzlibrary{arrows.meta, 
                bending,
                decorations.markings}

\begin{document}
\begin{frame}\centering
\begin{tikzpicture}[> = {Straight Barb[bend]}]
\draw [very thick, semitransparent,
       decoration={markings, mark=at position 0.27 with {\arrow[yshift=0.33\pgflinewidth,    % <---
                                                                red]{<}}},
       postaction={decorate}
      ]
        (0,0) circle[radius=12mm];
\end{tikzpicture}
\end{frame}
\end{document}

enter image description here

3
  • The outer border does not exist before rendering. If you make the radius small again, and choose a long arrow head (e.g. Stealth) then you can see what is happening: markings is finding the correct point on the path and switches to tangent coordinate system. The arrow can not do its normal shortening of the path and is therefore simply placed in the coordinate system. Sep 4 at 6:59
  • Also position 0.27 instead of 0.25 changes the direction. Sep 4 at 7:15
  • Thanks. I was able to attain what I wanted using the following code: \newcommand{\KPSS}[1]{% \begin{tikzpicture}[baseline=-\dimexpr\fontdimen22\textfont2\relax, scale=0.45, > = {Straight Barb[bend, length=1.8, angle'=85]}] #1 \end{tikzpicture}% } \newcommand{\KPSL}{% \kern -0.06em\KPSS{\filldraw[fill=none, thick, decoration={markings, mark=at position 0.25 with {\arrow[xshift=1.5, yshift=0.1\pgflinewidth]{<}}}, postaction={decorate}] circle (0.3);}% } Sep 4 at 11:31
4

With pstricks, it requires a very short code:

    \documentclass{article}
    \usepackage{pstricks, pst-arrow}

    \begin{document}

    \psset{unit=1cm, linejoin=1}
    \begin{pspicture}(-2,-2)(2,2)
    \psarcn[linewidth=1.5pt]{->}(0,0){2}{90}{-272}
    \end{pspicture}

    \end{document}[ArrowInside] 

enter image description here

4
  • The only problem is that I have a lot of other figures constructed using TikZ and I have configured them to look visually similar. I don't know how to achieve that in pstricks. Thanks for the answer anyway. Sep 3 at 14:06
  • 1
    @ApoorvPotnis it's quite common on this site for users to offer solutions to a problem using packages (or formats even!) different to that specified by the OP. This means that users with the same basic question but with different requirements can still find help, and it's a great way to learn about other packages which might be useful later on. I'm sure that someone will be along with a TikZ solution soon! Sep 3 at 16:15
  • The problem OP has comes partly from the small circle radius. This answer does not work without modifications when the radius is 0.3 cm. The arrow head is very different, so it does not really show the problem. Can you make these adjustments? Sep 4 at 2:12
  • @hpekristiansen: with a very small radius, I tried to modify some parameters, but it doesn't yield a very fine result. The extremity of the arrow is centred on the line, but the whole arrow is not symmetrical w.r.t. the centre of the line.
    – Bernard
    Sep 4 at 9:37
3

It's important to understand how the decorations.markings library works to see what's happening with your code. When it places a marking at a point on a path, then it applies a transformation so that the marking is based at the right place and so that it points along the path. However, it doesn't do anything else.

When an arrow is placed at the start or end of a path then a more complicated process takes place. Even without the bending library, then there are modifications applied to the path to ensure that the arrow ends at exactly the right place, and the path goes "into" the arrow at its base. With the bending library then even more complicated things happen.

The difference, then, is that with a decoration then the path is not used other than to place and rotate the arrow. This leads to the arrow not looking right - it doesn't end at the right place and it points out of the circle. One way to fix this is to use a path to draw the arrow. So we need a path that ends at the right point and follows the path of the circle up to it. We also want to just draw the arrow and not the path. And we'd like to not have to do too much "by hand".

Here's a solution that does that.

  1. We save a copy of the circle path,
  2. Using the spath3 library, we cut the path at the desired point (I found a bug in the code, so you'll need to use the current version from github until I upload it to CTAN). This path now ends at the right place.
  3. We now use this path to draw an arrow, and thanks to the tips key we can draw the arrow but not the path.
\documentclass{article}
%\url{https://tex.stackexchange.com/q/656033/86}

\usepackage{tikz}
\usetikzlibrary{
  shapes,
  decorations,
  arrows.meta,
  decorations.markings,
  bending,
  spath3
}

\begin{document}
\begin{tikzpicture}
\draw[
  thick,
  spath/save=circle
] circle[radius=0.3];
\tikzset{
  spath/remove empty components={circle},
  spath/split at={circle}{0.27},
}
\path[
  red,
  thick,
  tips=true,
  -{Straight Barb[length=2.15,reversed,bend]},
  spath/use=circle
];
\draw[
  green,
  line width=.05pt,
  spath/use=circle
  ];
\end{tikzpicture}
\end{document}

I've drawn the arrow in red and then placed a thin green circle over the top to show that the arrow does lie along the circular path as desired.

Arrow placed on path and curved along it

2
  • Thanks for the answer. I am not too keen on using the github version as don't know how to tinker with texlive packages. I shall wait until the package is updated on ctan. The code doesn't compile on my updated version of TeX Live as of now. Sep 5 at 17:29
  • @ApoorvPotnis Fair enough - I often develop code in order to figure out an answer on this site and it eventually works its way into one of my packages but I know that my hacks aren't for everyone. Sep 5 at 20:50
2
\documentclass[tikz, border=1cm]{standalone}
\usetikzlibrary{arrows.meta, bending}
\begin{document}
\begin{tikzpicture}
\filldraw[red, very thin] (0,0.5) -- (0,0) circle[radius=0.02];
\draw[thick, -{Straight Barb[length=2.15, sep=0pt -1]}] (90:0.3) arc[start angle=90, end angle=-270, radius=0.3];
\end{tikzpicture}
\end{document}

Circle with arrow head at top

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.