3

I am drawing a diagram with 27 points in three dimensions, three layers of nine points. What I would like to do is be able to prioritize how lines cross over each other. When I use "crossing over", one line seems to automatically cross over any other line it touches. For example, the line between 14 and 15 should overlap the line between 11 and 20 because it is more in the front, but the line between 9 and 18 should overlap the one between 14 and 15 because it is in the front. If I use "crossing over" for the 14->15, it overlaps 9->18, even if I use "crossing over" there, also. Here is the code I'm using:

\documentclass[12pt]{article}
\usepackage{tikz-cd}
\begin{document}
\begin{tikzcd}[cells={nodes={draw=gray}}, row sep=scriptsize, column sep=scriptsize]
& & & & 1 \arrow[dll, dash] \arrow[rrr, dash] \arrow[ddd, dash] & & & 2 \arrow[dll, dash] \arrow[rrr, dash] \arrow[ddd, dash] & & & 3 \arrow[dll, dash] \arrow[ddd, dash] \\
& & 4 \arrow[dll, dash] \arrow[rrr, crossing over, dash] \arrow[ddd, dash] & & & 5 \arrow[dll, crossing over, dash] \arrow[rrr, crossing over, dash] \arrow[ddd, dash] & & & 6 \arrow[dll, crossing over, dash] \arrow[ddd, dash] & &\\
 7 \arrow[rrr, crossing over, dash] \arrow[ddd, dash] & & & 8 \arrow[rrr, crossing over, dash] \arrow[ddd, dash] & & & 9 \arrow[ddd, crossing over, dash] & & & &\\
 & & & & 10 \arrow[dll, dash] \arrow[rrr, dash] \arrow[ddd, dash] & & & 11 \arrow[dll, dash] \arrow[rrr, dash] \arrow[ddd, dash] & & & 12 \arrow[dll, dash] \arrow[ddd, dash] \\
& & 13 \arrow[dll, dash] \arrow[rrr, crossing over, dash] \arrow[ddd, dash] & & & 14 \arrow[dll, dash] \arrow[rrr, crossing over, dash] \arrow[ddd, dash] & & & 15 \arrow[dll, dash] \arrow[ddd, dash] & &\\
 16 \arrow[rrr, crossing over, dash] \arrow[ddd, dash] & & & 17 \arrow[rrr, crossing over, dash] \arrow[ddd, dash] & & & 18 \arrow[ddd, dash] & & & &\\
& & & & 19 \arrow[dll, dash] \arrow[rrr, dash] & & & 20 \arrow[dll, dash] \arrow[rrr, dash] & & & 21 \arrow[dll, dash] \\
& & 22 \arrow[dll, dash] \arrow[rrr, crossing over, dash] & & & 23 \arrow[dll, dash] \arrow[rrr, crossing over, dash] & & & 24 \arrow[dll, dash] & &\\
25 \arrow[rrr, crossing over, dash] & & & 26 \arrow[rrr, crossing over, dash] & & & 27 & & & &\\
\end{tikzcd}
\end{document}

Thank you for your help!

1

You can defer the arrow using from key. For example from 9 don't draw the arrow to 18 but from 18 draw it like

18  \arrow[from=uuu, crossing over]

so that it appears to be on top.

\documentclass[12pt]{article}
\usepackage{tikz-cd}
\begin{document}
\begin{tikzcd}[cells={nodes={draw=gray}}, row sep=scriptsize, column sep=scriptsize]
& & & & 1 \arrow[dll, dash] \arrow[rrr, dash] \arrow[ddd, dash] & & & 2 \arrow[dll, dash] \arrow[rrr, dash] \arrow[ddd, dash] & & & 3 \arrow[dll, dash] \arrow[ddd, dash] \\
& & 4 \arrow[dll, dash] \arrow[rrr, crossing over, dash] \arrow[ddd, dash] & & & 5 \arrow[dll, crossing over, dash] \arrow[rrr, crossing over, dash] \arrow[ddd, dash] & & & 6 \arrow[dll, crossing over, dash] & &\\
 7 \arrow[rrr, crossing over, dash] \arrow[ddd, dash] & & & 8 \arrow[rrr, crossing over, dash] & & & 9 & & & &\\
 & & & & 10 \arrow[dll, dash] \arrow[rrr, dash] \arrow[ddd, dash] & & & 11 \arrow[dll, dash] \arrow[rrr, dash] \arrow[ddd, dash] & & & 12 \arrow[dll, dash] \arrow[ddd, dash] \\
& & 13 \arrow[dll, dash] \arrow[rrr, crossing over, dash] \arrow[ddd, dash] & & & 14 \arrow[ddd,crossing over,dash]\arrow[rrr, crossing over, dash] \arrow[ddd, dash] & & & 15 \arrow[from=uuu,crossing over, dash]& &\\
 16 \arrow[rrr, crossing over, dash] \arrow[ddd, dash] & & & 17 \arrow[from=rru,crossing over, dash] \arrow[from=uuu,crossing over, dash]\arrow[rrr, crossing over, dash] & & & 18 \arrow[from=rru,crossing over, dash] \arrow[from=uuu, crossing over,dash] & & & &\\
& & & & 19 \arrow[dll, dash] \arrow[rrr, dash] & & & 20 \arrow[dll, dash] \arrow[rrr, dash] & & & 21 \arrow[dll, dash] \\
& & 22 \arrow[dll, dash] \arrow[rrr, crossing over, dash] & & & 23 \arrow[dll, dash] \arrow[rrr, crossing over, dash] & & & 24 \arrow[from=uuu,crossing over, dash] \arrow[dll, dash] & &\\
25 \arrow[rrr, crossing over, dash] & & & 26 \arrow[from=uuu,crossing over, dash]\arrow[rrr, crossing over, dash] & & & 27 \arrow[from=uuu,crossing over, dash]& & & &\\
\end{tikzcd}
\end{document}

enter image description here

3
  • This works almost everywhere. The lines I'm still having trouble getting correct are the 5 -> 14 and 14 -> 23 lines. They are under correctly, but should cross over 10 ->11 and 19 -> 20, respectively. If I switch up the order and do 14 -> 5 so that it crosses over correctly, it won't go under correctly. Is there a way around that? Thanks again!
    – user112597
    Oct 19 '15 at 20:58
  • @user112597 That will require some hack I am afraid. You have to insert a phantom row in between and draw two arrows, one below and one above.
    – user11232
    Oct 19 '15 at 22:28
  • OK, thank you! I had played around with it but had exhausted the possibilities I knew of.
    – user112597
    Oct 20 '15 at 23:17

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.