# how to "design" and code a 3x3x3 3d diagram in tikz-cd

I need to do a 3x3x3 diagram in tikz-cd and I'm wondering what's the best way to code it to make ti as clear as possible.

I've a little experience with 2x2x2 diagrams in tikz-cd using crossing-over, but when it comes to 3x3x3 the crossing over command fails:

\documentclass[11pt,a4paper]{article}
\usepackage[left=2cm,right=2cm,top=2.5cm,bottom=2.5cm]{geometry}
\usepackage{tikz-cd}
\newlength{\perspective}
\begin{document}
\begin{tikzcd}[row sep=1.5em, column sep =.1]
(k-1,j-1,i-1) \arrow{ddd} \arrow{dr}& &  & (k,j-1,i-1) \arrow{lll} \arrow{ddd}\arrow{dr}& &  & \\
{} & (k-1,j-1,i)\arrow[ddd, crossing over]\arrow{dr}&  & & (k,j-1,i)  \arrow[lll, crossing over]\arrow{ddd}\arrow{dr} &  & \\
{} & & (k-1,j-1,i+1)\arrow{ddd} & & & (k,j-1,i+1) \arrow{ddd}\arrow[lll, crossing over]&{}\\
(k-1,j,i-1)\arrow[ddd, crossing over]\arrow{dr} & &  & (k,j,i-1)  \arrow{lll}\arrow{ddd}\arrow{dr} & &  & \\
{} & (k-1,j,i)\arrow{ddd}\arrow{dr}&  & & (k,j,i) \arrow[lll, crossing over]\arrow{ddd}\arrow{dr}&  & \\
{} & & (k-1,j,i+1)\arrow{ddd} & & & (k,j,i+1) \arrow{lll}\arrow{ddd} &{}\\
(k-1,j+1,i-1)\arrow{dr} & &  & (k,j+1,i-1) \arrow{lll}\arrow{dr} & &  & \\
{} & (k-1,j+1,i)\arrow{dr}&  & & (k,j+1,i)\arrow{dr} \arrow{lll} &  & \\
{} & & (k-1,j+1,i+1) & & & (k,j+1,i+1) \arrow{lll} &{}
\end{tikzcd}

\end{document}


As you can see, the arrow from (k,j,i) to (k-1,j,i) should be UNDER the vertical arrow starting at (k-1,j-1,i+1) but I don't know how to control it. Is there some ready-made 3x3x3 diagram or some resources where I can learn how to code these kind of big diagrams with the correct over and underlapping?

I found an "isometric" way to draw diagrams in tikz-cd which might improve readability by a lot (https://tex.stackexchange.com/a/234151/47869) but I'm not sure how this \isofactor and \perspective commands work. IS there any resource for understanding how to design an isometric 3x3x3 diagram in tikz-cd?

• cross-over arrows should be written after the arrows in the back. One option is to add an alias to the necessary entries and write those arrows at the end of the enviroment, in the form \arrow[from=label1, to=label2, crossing over,...] May 3, 2022 at 2:23
• Thanks! What do you mean adding it at the end of the environment? (I’m a casual latex user…) May 3, 2022 at 2:33

Build your diagram from "back" to "front", crossing over when necessary. One way to make this easier to write and edit is to draw all your arrows at the end using the syntax \arrow[from=r1-c1,to=r2-c2] (row and column numbers).

\documentclass{article}
\usepackage{tikz-cd}

\begin{document}
\begin{tikzcd}[row sep=1.5em, column sep =.1]
(k-1,j-1,i-1) & &  & (k,j-1,i-1) & & \\
& (k-1,j-1,i) &  &  & (k,j-1,i) &  & \\
& & (k-1,j-1,i+1) & & & (k,j-1,i+1) & \\
(k-1,j,i-1) & & & (k,j,i-1) & & \\
& (k-1,j,i) & & & (k,j,i) &  \\
& & (k-1,j,i+1) & & & (k,j,i+1) \\
(k-1,j+1,i-1) & &  & (k,j+1,i-1) & &   \\
& (k-1,j+1,i) &  & & (k,j+1,i) &  \\
& & (k-1,j+1,i+1) & & & (k,j+1,i+1)
\arrow[from=1-1,to=4-1]\arrow[from=4-1,to=7-1]
\arrow[from=1-4,to=4-4]\arrow[from=4-4,to=7-4]
\arrow[from=1-4,to=1-1]\arrow[from=7-4,to=7-1]
\arrow[from=4-4,to=4-1]
\arrow[from=2-2,to=5-2, crossing over]\arrow[from=5-2,to=8-2, crossing over]
\arrow[from=2-5,to=5-5]\arrow[from=5-5,to=8-5]
\arrow[from=2-5,to=2-2, crossing over]\arrow[from=8-5,to=8-2]
\arrow[from=5-5,to=5-2, crossing over]
\arrow[from=3-3,to=6-3, crossing over]\arrow[from=6-3,to=9-3, crossing over]
\arrow[from=3-6,to=6-6]\arrow[from=6-6,to=9-6]
\arrow[from=3-6,to=3-3, crossing over]\arrow[from=9-6,to=9-3]
\arrow[from=6-6,to=6-3, crossing over]
\arrow[from=1-1,to=2-2]\arrow[from=2-2,to=3-3]
\arrow[from=4-1,to=5-2]\arrow[from=5-2,to=6-3]
\arrow[from=7-1,to=8-2]\arrow[from=8-2,to=9-3]
\arrow[from=1-4,to=2-5]\arrow[from=2-5,to=3-6]
\arrow[from=4-4,to=5-5]\arrow[from=5-5,to=6-6]
\arrow[from=7-4,to=8-5]\arrow[from=8-5,to=9-6]
\end{tikzcd}

\end{document}


This should be a comment but it is rather long. The answer given by Sandy G is great, adequate and contains the main idea, crossing over arrows should be written after the arrows in the back (+1). Anyway, maybe the OP has a better way to remember the objects in the diagram than coordinates. In that case adding an alias key to the objects could be a good way. This is far from an answer but the idea is as follows:

\documentclass{article}
\usepackage{tikz-cd}
\begin{document}
\begin{tikzcd}
|[alias=x]|A & B\arrow{ld}\\
C & |[alias=y]|D
\arrow[from=1-1, to=2-2]%using coordinates
\arrow[blue, from=x, to=y, crossing over]%using a good name to the objects in the diagram
\end{tikzcd}
\end{document}