In a Tikz commutative diagram, I would like to draw two parallel arrows that cross over. Something like this:

A x B

|   |
|   |
 \ /
  X  f
 / \
|   |
V   V

C x D

(of course I would prefer the arrows to bend smoothly rather than have sharp corners).

(Here f is a map from the product A x B to the product C x D, and I want to visually suggest the fact this if f sends say a pair (a, b) to a pair (c, d), then c depends only on b and not on a, and d depends only on a and not on b.)

Does anyone know a simple way to do this? If it is impossible in Tikz-CD, maybe it is possible with another package?

Bonus points if it is possible to adjust the separation between the two arrows.

  • Not quite clear… Could you post a hand-made sketch of what you'd like to obtain? – Bernard Oct 16 '16 at 20:09
  • Here is an ASCII-art picture that hopefully makes it clear what I would like to get. – Ilia Smilga Oct 16 '16 at 21:11
  • The entries in the diagram are named so it should not be a problem to make what Zarko did. There are some examples of this at the end of the manual for tikz-cd (not at a pc, so cannot test) – daleif Oct 17 '16 at 10:59

If you need to do this frequently, you'll want a tikz style for it. Here's a style which you can add to a tikz-cd arrow to make it show up as a crossover:

\usetikzlibrary{calc, decorations.pathreplacing}

  crossover/.style = {
    decoration={show path construction, lineto code={
      \coordinate (crossovertikzinputsegmentfirst) at (\tikzinputsegmentfirst);
      \coordinate (crossovertikzinputsegmentlast) at (\tikzinputsegmentlast);
      \path ([shift=(90+\ang:#1)] \tikzinputsegmentfirst) edge[out=\ang, in=180+\ang] ([shift=(-90+\ang:#1)] \tikzinputsegmentlast)
            ([shift=(-90+\ang:#1)] \tikzinputsegmentfirst) edge[out=\ang, in=180+\ang] ([shift=(90+\ang:#1)] \tikzinputsegmentlast);
    commutative diagrams/labels={inner sep=#1},

A \times B \arrow[crossover=2ex]{d}{f} \arrow[crossover]{r}{g} & F\\
C \times D 

The optional argument is (half) the distance between the arrows.



Like this?

enter image description here

This is pure TikZ solution:

\usetikzlibrary{arrows.meta, bending, calc, chains, positioning}
node distance = 24mm and 0mm,
  start chain = A going right,
  line/.style = {line width=1mm, draw=gray, -Stealth[bend]}
\begin{scope}[every node/.style = {minimum size= 7mm, outer sep=0pt, 
                                   font=\Large, on chain=A}]
\node   {$A$};              % <-- name: A-1
\node   {$\times$};
\node   {$B$};
\node[below=of A-1] {$C$};  % <-- name: A-4
\node   {$\times$};
\node   {$D$};
\coordinate[label={[xshift=1mm]right:$f$}] (x) at ($(A-2)!0.4!(A-5)$);
\draw[line] (A-1) to [out=-90, in=135] (x) to [out=- 45, in=90] (A-6); 
\draw[line] (A-3) to [out=-90, in= 45] (x) to [out=-135, in=90] (A-4);
  • Is it possible to have something more in line with the standard tikz-cd arrows? – egreg Oct 17 '16 at 7:28
  • @egreg, maybe it is possible. I'm not familiar with this TikZz derivative, so I consider "maybe it is possible with another package" part of OP question ... – Zarko Oct 17 '16 at 8:53
  • Thank you. I'll take this if there is nothing else, but a way to do it in some higher-level package would be really nice. What I gave here is a MWE, but the complete diagram I want to draw is slightly more complex and adjusting everything by hand will be a pain. – Ilia Smilga Oct 17 '16 at 23:19

Here is what I finally did. The code has a couple of issues:

  • for some reason the label disappeared when I added the "to path" option, so I drew an invisible (white) arrow in order to print the label;
  • it would probably abstract away the magical number "1ex" into a variable defined once and for all (but I do not know how to do this in TikZ);

but it works.



A \times B
  \arrow[white]{dd}{{\color{black} \hspace{1ex} f}}
  \arrow[rounded corners, to path =
    -- ([xshift=-1ex, yshift=1ex]$(\tikztostart.south)!.5!(\tikztotarget.north)$)
    -- ([xshift=1ex, yshift=-1ex]$(\tikztostart.south)!.5!(\tikztotarget.north)$)
    -- ([xshift=1ex]\tikztotarget.north)}]{dd}
  \arrow[rounded corners, to path =
    -- ([xshift=1ex, yshift=1ex]$(\tikztostart.south)!.5!(\tikztotarget.north)$)
    -- ([xshift=-1ex, yshift=-1ex]$(\tikztostart.south)!.5!(\tikztotarget.north)$)
    -- ([xshift=-1ex]\tikztotarget.north)}]{dd}\\
C \times D


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.