I'm trying to draw a single link diagram (like the one here: https://loopspace.mathforge.org/HowDidIDoThat/TeX/Knots/#section.5) using the knots library:

  flip crossing=2
\strand (1,0) circle[radius=2cm];
\strand[blue] (-1,0) circle[radius=2cm];

However, I'd like one of my circles to have two colours. The idea is that the link represents the closure of a three-strand braid, and one of the circles in the link comes from two of the strands, so I thought it would be nice to colour it to show that.

Initially, I was thinking of something like this: How to draw a double-color line with tikz . However, when I changed my \strand[blue] to \strand[draw=blue,dash pattern= on 3pt off 5pt,thick,postaction={draw,red,dash pattern= on 3pt off 5pt,dash phase=4pt,thick}](-1,0) circle[radius=2cm];, the crossing gaps no longer show up:

enter image description here

I also tried an alternative approach using a gradient from this question Path following color gradient in TikZ, but, again, the crossing gaps vanished.

I'm assuming the knot library is somehow not applying the gap rule to the postaction / decoration? Is there an appropriate way to draw a two-coloured strand using the knots library?

  • 1
    Why do you need knot library? You can realize the drawing from scratch.
    – Daniel N
    Jan 16 at 16:46
  • 1
    Things like a dash pattern should be put in the only when rendering key. The knots library uses a copy of the strand to "wipeout" the understand, so you don't want it to have gaps when it does so. Jan 16 at 18:42
  • 1
    And I'm not sure I've ever investigated a postaction with strands. To be on the save side, I'd put that in the only when rendering key as well. Jan 16 at 18:44
  • aha! so simple you when you know :-)
    – MairAW
    Jan 16 at 21:17
  • 1
    As a tip, setting background colour=yellow or some other non-background colour can be very useful to see what's going on. This shows what the "cutting path" looks like. Removing the postaction (as that has other issues) but keeping the dash pattern shows that the lower intersection point gets missed by the dash on the cutting path. Jan 16 at 22:47

1 Answer 1

\documentclass[tikz, border=1cm]{standalone}
flip crossing=2,
clip width=10,
\strand[red, thick] (1,0) circle[radius=1.3cm];
blue, thick,
only when rendering/.style={dash pattern=on 3pt off 5pt},
preaction={draw, red, thick, dash pattern=on 3pt off 5pt, dash phase=4pt},
](-0.5,0) circle[radius=1.3cm];

Two circle knot with red blue dash pattern

  • thank you! it works perfectly
    – MairAW
    Jan 16 at 21:20
  • I note that you switched to a preaction. I'm pretty sure that I've investigated this before (contrary to my comment on the question!) and found a difference in how pre and post actions work, to the effect that a postaction will clobber how knots works but a preaction won't. I can't find the relevant .tex file in my folder of test files, though! Jan 16 at 22:46
  • @AndrewStacey: I did not read your comments before posting my solution. I was just experimenting and found the needed only when rendering in the manual. I have no real idea of what I am doing - most of my solutions are just working experiments with no insight. Thanks for the knots package - it has solved many problems on this site. Jan 17 at 13:32
  • @hpekristiansen I'm taking it as a win that you figured it out from the documentation - it's not one of my strengths ... Jan 17 at 21:15

You must log in to answer this question.

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