7

Is there anyway to combine hobby paths and lines into a single path so that I can apply a post-action?

Basically, I want my orientation arrows to be equally spaced along the entire path rather than the individual components.

\documentclass{standalone}

\usepackage{tikz}
\usetikzlibrary{hobby}
\usetikzlibrary{backgrounds}
\usetikzlibrary{decorations.markings}
\usetikzlibrary{arrows.meta}
\tikzset{>=stealth}

\tikzset{
  clockwise arrows/.style={
    postaction={
      decorate,
      decoration={
        markings,
        mark=between positions 0 and 1 step 40pt with {\arrow{>}},
   }}}}

\begin{document}
\begin{tikzpicture}[framed]

\coordinate (B1) at (7,-1);
\coordinate (B2) at (7,1);

\coordinate (A1) at (1,2);
\coordinate (A2) at (1,-2);

\draw[magenta, thick, clockwise arrows] (A1) -- (A2);
\draw[magenta, thick, clockwise arrows] (B1) -- (B2);

\draw[magenta,thick,use Hobby shortcut, clockwise arrows] (B2) .. (4.5,2) .. (3,3) .. (A1);
\draw[magenta,thick,use Hobby shortcut, clockwise arrows] (A2) .. (3,-3) .. (4.5,-2) .. (B1);

\end{tikzpicture}
\end{document}

Note arrows are not equally spaced.

  • 1
    What goes wrong if you just put them into a single path command? That ought to work just fine. – Loop Space Sep 30 '16 at 5:29
  • How do I do that :S ? – vrbatim Sep 30 '16 at 7:33
9

You can combine your four draw statements into a single statement:

\draw[magenta,thick,use Hobby shortcut, clockwise arrows] 
    (B2) .. (4.5,2) .. (3,3) .. (A1) -- 
    (A2) .. (3,-3) .. (4.5,-2) .. (B1) -- cycle;

Note that you can mix .. and -- and that cycle closes the loop.

But, you will still get that horrible arrow at the start of the path. To fix that you could just make the decoration start a bit further along:

    mark=between positions 0.05  and 1 step 40pt with {\arrow{>}},

with these changes your example produces this:

enter image description here

  • Couldn't have put it better myself! – Loop Space Sep 30 '16 at 16:13
  • @LoopSpace I'm sure you could. – Thruston Sep 30 '16 at 18:53

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.