4

I'm using tikzcd to draw diagrams. I want one line to cross another at (and only at) the intersection. I use the crossing over option. But there is something else being covered. Here is my code.

\documentclass{article}
\usepackage{tikz-cd}
\begin{document}
\begin{tikzcd}
  X_1 &X_2 &X_3\ar[dll]\\
  Y_1 &Y_2 &Y_3
  \ar[from=1-2,crossing over]
  \ar[from=1-1,crossing over]
\end{tikzcd}
\end{document}

The picture is the result. I draw a red cycle manually to emphasize arrow. Part of the head of the arrow from $X_2$ to $Y_3$ is covered. enter image description here

So, is there some method to make the crossing over only at the intersections? Thank you for some suggestions.

2
  • Can you add a complete MWE so I can see your package, please?
    – Sebastiano
    Commented Feb 14, 2017 at 7:45
  • @Sebastiano I just use tikz-cd. I complete the code.
    – jiaopjie
    Commented Feb 14, 2017 at 7:52

3 Answers 3

2

This is probably not the most elegant solution, but one approach with TikZ.

It draws white circles between the arrow in the background and the arrows in the foreground at the intersections.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix,intersections}
\pgfdeclarelayer{fg}
\pgfdeclarelayer{crossing over}
\pgfsetlayers{main,crossing over,fg}
\begin{document}
\begin{tikzpicture}
    \matrix (m) [matrix of math nodes, column sep=1cm, row sep=1cm, circle] {
        X_1 &X_2 &X_3 \\
        Y_1 &Y_2 &Y_3 \\
    };
    \draw[->, name path=bg arrow]  (m-1-3) -- (m-2-1);
    \begin{pgfonlayer}{fg}
        \draw[->, name path global/.expanded=fg arrow1] (m-1-1) -- (m-2-3);
        \draw[->, name path global/.expanded=fg arrow2] (m-1-2) -- (m-2-3);
    \end{pgfonlayer}
    \begin{pgfonlayer}{crossing over}
        \foreach \arrow in {1, ..., 2} {
            \fill[white, name intersections={of=bg arrow and fg arrow\arrow, name=i}] (i-1) circle (2pt);
        }
    \end{pgfonlayer}
\end{tikzpicture}
\end{document}

Edit: Alternative code producing same output but avoiding several layers:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix,intersections}
\makeatletter
% http://tex.stackexchange.com/a/127045/120953
\tikzset{use path/.code=\tikz@addmode{\pgfsyssoftpath@setcurrentpath#1}}
\makeatother
\begin{document}
\begin{tikzpicture}
    \matrix (m) [matrix of math nodes, column sep=1cm, row sep=1cm, circle] {
        X_1 &X_2 &X_3 \\
        Y_1 &Y_2 &Y_3 \\
    };
    \draw[->, name path=bg arrow]  (m-1-3) -- (m-2-1);
    \path[name path=fg arrow1, save path=\pathFGone] (m-1-1) -- (m-2-3);
    \path[name path=fg arrow2, save path=\pathFGtwo] (m-1-2) -- (m-2-3);
    \foreach \arrow in {1, ..., 2} {
        \fill[white, name intersections={of=bg arrow and fg arrow\arrow, name=i}] (i-1) circle (2pt);
    }
    \draw[->, use path=\pathFGone];
    \draw[->, use path=\pathFGtwo];
\end{tikzpicture}
\end{document}
2
  • It seems that the layer crossing over covers main and fg covers crossing over. Is it possible to use the cycle built by \fill command covers the path from (m-1-3) to (m-2-1) by changing the order of the commands and without using pfgonlayer? It seems that i can draw (m-1-3)--(m-2-1) and an empty (m-1-1)--(m-2-3). Then place an empty cycle at the intersection. Then draw a black (m-1-1)--(m-2-3). Then could the name intersections compute the intersection of (m-1-3)--(m-2-1) and (m-1-1)--(m-2-3) before drawing (m-1-1)--(m-2-3)?
    – jiaopjie
    Commented Feb 14, 2017 at 12:15
  • @jiaopjie yes, it is possible to avoid pgfonlayer. see my edited answer.
    – jakun
    Commented Feb 15, 2017 at 10:19
5

I resolve your question reducing the lenght of one arrow from X_1 to Y_3. I hope it goes well. Generally I try change slightly every MWE.

enter image description here

\documentclass{article}
\usepackage{tikz-cd}
\begin{document}
\begin{tikzcd}[column sep = large, row sep = large]
  X_1 &X_2 &X_3\ar[dll]\\
  Y_1 &Y_2 &Y_3
  \ar[from=1-2,crossing over]
  \ar[from=1-1,crossing over, shorten >= 5pt]
\end{tikzcd}
\end{document}
2

One very simple solution is redrawing the first crossing arrow without the cross over option.

\documentclass{standalone}
\usepackage{tikz-cd}
\begin{document}
\begin{tikzcd}
  X_1 &X_2 &X_3\ar[dll]\\
  Y_1 &Y_2 &Y_3
  \ar[from=1-2,crossing over]
  \ar[from=1-1,crossing over]
  \ar[from=1-2]
\end{tikzcd}
\end{document}

result

If you don't like how the top of the arrows are arranged you can additionally use Sebastiano's answer and shorten one of the arrows a little bit, e.g., \ar[from=1-1,crossing over,shorten=2pt].

You must log in to answer this question.

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