Cross over of arrows in a complex diagram
With crossing over
, arrows that are drawn later, erase part of the arrows they cross.
\documentclass{article}
\usepackage{geometry}
\usepackage{amsmath}
\usepackage{tikz-cd}
\newcommand{\level}{\mathrm{Level}}
\begin{document}
\begin{tikzcd}[column sep=1.5em,row sep=large,arrows={crossing over}]
&&
\level(1,3)
\\ \\
&
\level(2,2) \arrow[uur] &
\level(2,3) \arrow[uu] \arrow[rr,thick,equals] &&
\level(2,5) \arrow[rr] \arrow[ddl,leftarrow] &&
\level(2,7) \arrow[ddl,thick,equals]
\\
&&
\level(3,3) \arrow[u] \arrow[rr] \arrow[ddl,leftarrow] &&
\level(3,5) \arrow[u,thick,equals] \arrow[rr] \arrow[ddl,leftarrow] &&
\level(3,7) \arrow[u,thick,equals]
\\
\level(4,1) \arrow[uur,thick,equals] &
\level(4,2) \arrow[uu] \arrow[rr] \arrow[uur] &&
\level(4,4) \arrow[rr] \arrow[ddl,leftarrow] &&
\level(4,6) \arrow[ddl,leftarrow]
\\
&
\level(5,2) \arrow[u] \arrow[rr] \arrow[ddl,leftarrow] &&
\level(5,4) \arrow[u] \arrow[rr] &&
\level(5,6) \arrow[u,thick,equals] \arrow[uur]
\\
\level(6,1) \arrow[uu] \arrow[uur,thick,equals] \arrow[rr] &&
\level(6,3) \arrow[rr] &&
\level(6,5)
\\
\level(7,1) \arrow[u] \arrow[rr] &&
\level(7,3) \arrow[u] \arrow[rr] &&
\level(7,5) \arrow[u] \arrow[uur]
\end{tikzcd}
\end{document}
The standard trick for this is to draw a thick white line underneath, which can be achieved with preaction
. This answer comes with a style on top
, which can be used like (m-6-5) edge[on top] (m-4-6)
. You need to draw the topmost connections last. At the moment, the default line widths of the white lines is 4pt
but you can adjust them to your needs.
\documentclass[border=5mm]{standalone}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}[on top/.style={preaction={draw=white,-,line width=#1}},
on top/.default=4pt]
\matrix (m) [matrix of math nodes, row sep=1.6cm,
column sep=0.4cm]{
&&Level(1,3)&&&&\\
&Level(2,2)&Level(2,3)&& Level(2,5)&&Level(2,7)\\
&&Level(3,3)&& Level(3,5)&&Level(3,7)\\
Level(4,1)&Level(4,2)&& Level(4,4)&&Level(4,6)& \\
&Level(5,2)&& Level(5,4)&&Level(5,6)& \\
Level(6,1)&& Level(6,3)&& Level(6,5)&&\\
Level(7,1) && Level(7,3)&& Level(7,5)&&\\};
\path[-stealth]
(m-7-1) edge (m-7-3) edge (m-6-1)
(m-7-3) edge (m-7-5)
edge (m-6-3)
(m-7-5) edge (m-6-5)
edge (m-5-6)
(m-6-1) edge (m-4-1)
(m-6-3) edge (m-6-5)
(m-5-4) edge (m-4-4)
(m-5-2) edge (m-5-4)
edge (m-4-2)
edge (m-3-3)
(m-5-4) edge (m-5-6)
edge (m-3-5)
(m-5-6) edge (m-3-7)
(m-4-2) edge (m-2-2)
edge (m-2-3)
(m-3-3) edge (m-2-3)
edge (m-3-5)
(m-3-5) edge (m-3-7)
(m-2-2) edge (m-1-3)
(m-2-3) edge (m-1-3)
(m-2-5) edge (m-2-7)
(m-4-2) edge[on top] (m-4-4)
(m-4-4) edge[on top] (m-4-6)
(m-6-5) edge[on top] (m-4-6)
(m-4-4) edge[on top] (m-2-5)
(m-6-3) edge[on top] (m-4-4)
;
\path[>=stealth,-,thick]
(m-7-1) edge [double] (m-5-2)
(m-6-1) edge [double] (m-4-2)
(m-5-6) edge [double] (m-4-6)
(m-4-1) edge [double] (m-2-2)
(m-3-5) edge [double] (m-2-5)
(m-3-7) edge [double] (m-2-7)
(m-2-3) edge [double] (m-2-5)
(m-4-6) edge [double,on top=5pt] (m-2-7)
;
\path[-stealth] (m-6-1) edge[on top] (m-6-3) ;
\end{tikzpicture}
\end{document}
@egreg called this code "awkward". The IMHO most redundant thing, however, is IMHO that one has to add the position of the entry by hand (but I do not like to use words like "awkward"). In any case, this can be made as easily as defining a style
level/.style={
execute at begin node={\text{Level}(\the\pgfmatrixcurrentrow,\the\pgfmatrixcurrentcolumn)}
}
which gets used in the following code, which also has some loops to draw the arrows.
\documentclass[border=5mm]{standalone}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}[on top/.style={preaction={draw=white,-,line width=#1}},
on top/.default=4pt,level/.style={
execute at begin node={\text{Level}(\the\pgfmatrixcurrentrow,\the\pgfmatrixcurrentcolumn)}
}]
\matrix (m) [matrix of math nodes,nodes=level,row sep=1.6cm,
column sep=0.4cm]{
&&{}&&&&\\
&{}&{}&& {}&&{}\\
&&{}&& {}&&{}\\
{}&{}&& {}&&{}& \\
&{}&& {}&&{}& \\
{}&& {}&& {}&&\\
{} && {}&& {}&&\\};
\path[-stealth]
(m-6-1) edge (m-4-1) (m-4-2) edge (m-2-2) (m-2-3) edge (m-1-3)
(m-4-2) edge (m-2-3) (m-5-2) edge (m-3-3)
(m-5-4) edge (m-3-5) (m-7-5) edge (m-5-6) (m-5-6) edge (m-3-7)
(m-2-2) edge (m-1-3);
\path[-stealth,every edge/.append style={on top}]
foreach \Y [count=\Z] in {3,5,7}{
foreach \X in {1,3,5}
{(m-\Y-\the\numexpr\X+3-\Z\relax) edge (m-\the\numexpr\Y-1\relax-\the\numexpr\X+3-\Z\relax)
\ifnum\X<5
(m-\Y-\the\numexpr\X+3-\Z\relax) edge (m-\Y-\the\numexpr\X+5-\Z\relax)
\ifnum\the\numexpr\Y*10+\X=31
\else
(m-\the\numexpr\Y-1\relax-\the\numexpr\X+3-\Z\relax) edge (m-\the\numexpr\Y-1\relax-\the\numexpr\X+5-\Z\relax)
\fi
\fi
}} (m-4-4) edge (m-2-5) (m-6-3) edge (m-4-4);
\path[thick,every edge/.append style={double,on top=5pt}]
(m-4-1) edge (m-2-2) (m-6-1) edge (m-4-2) (m-7-1) edge (m-5-2)
(m-2-3) edge (m-2-5) (m-2-7) edge (m-3-7)
(m-2-7) edge (m-4-6) (m-4-6) edge (m-6-5);
\path[-stealth,every edge/.append style={on top}] (m-6-1) edge (m-6-3);
\end{tikzpicture}
\end{document}
This information, together with this answer, allows one to simplify egreg's answer and to correct the arrows there (such that there is a 3D impression).
\documentclass{article}
\usepackage{geometry}
\usepackage{amsmath}
\usepackage{tikz-cd}
\usetikzlibrary{backgrounds}
\newcommand{\level}{\text{level}(\the\pgfmatrixcurrentrow,\the\pgfmatrixcurrentcolumn)}
\begin{document}
\begin{tikzcd}[column sep=1.5em,row sep=large,arrows={crossing over},
execute at end picture={
\begin{scope}[on background layer]
\path[->] (\tikzcdmatrixname-6-2) edge (\tikzcdmatrixname-6-4)
(\tikzcdmatrixname-6-4) edge (\tikzcdmatrixname-6-6)
(\tikzcdmatrixname-4-5) edge (\tikzcdmatrixname-4-7);
\end{scope}}]
&&
\level
\\ \\
&
\level \arrow[uur] &
\level \arrow[uu] \arrow[rr,thick,equals] &&
\level \arrow[rr] \arrow[ddl,leftarrow] &&
\level \arrow[ddl,thick,equals]
\\
&&
\level \arrow[u] \arrow[ddl,leftarrow] &&
\level \arrow[u,thick,equals] \arrow[ddl,leftarrow] &&
\level \arrow[u,thick,equals]
\\
\level \arrow[uur,thick,equals] &
\level \arrow[uu] \arrow[rr] \arrow[uur] &&
\level \arrow[rr] \arrow[ddl,leftarrow] &&
\level \arrow[ddl,leftarrow]
\\
&
\level \arrow[u] \arrow[ddl,leftarrow] &&
\level \arrow[u] &&
\level \arrow[u,thick,equals] \arrow[uur]
\\
\level \arrow[uu] \arrow[uur,thick,equals] \arrow[rr] &&
\level \arrow[rr] &&
\level
\\
\level \arrow[u] \arrow[rr] &&
\level \arrow[u] \arrow[rr] &&
\level \arrow[u] \arrow[uur]
\end{tikzcd}
\end{document}