TikZ: Commutative diagrams with crossing edges

When one edge of a graph passes over or under another edge there may be a small gap needed in the drawing of one of those edges. An easy trick is to draw the upper edge two times: first with the background color and more thickness, afterwards normally, like
<node1> edge [-,line width=6pt,draw=white] <node2> edge <node2>
Here’s an example diagram used in the definition of the pull-back of a Banach bundle:

Tikz commutative diagram

The source code:

\begin{tikzpicture}
  \matrix (m) [matrix of math nodes, row sep=3em,
    column sep=3em]{
    & f^\ast E_V& & \vphantom{f^\ast}E_V \\
    f^\ast E & & \vphantom{f^\ast}E & \\
    & U & & V \\
    M & & N & \\};
  \path[-stealth]
    (m-1-2) edge (m-1-4) edge (m-2-1)
            edge [densely dotted] (m-3-2)
    (m-1-4) edge (m-3-4) edge (m-2-3)
    (m-2-1) edge [-,line width=6pt,draw=white] (m-2-3)
            edge (m-2-3) edge (m-4-1)
    (m-3-2) edge [densely dotted] (m-3-4)
            edge [densely dotted] (m-4-1)
    (m-4-1) edge (m-4-3)
    (m-3-4) edge (m-4-3)
    (m-2-3) edge [-,line width=6pt,draw=white] (m-4-3)
            edge (m-4-3);
\end{tikzpicture}

This topic was discussed on Matheplanet.com.

If you want to read more about commutative diagrams with TikZ have a look here: Chains with labeled edges.

07. January 2009 by stefan
Categories: Graphics, Mathematics, pgf/TikZ | 5 comments

Comments (5)

  1. Nice trick. Doing this kind of thing automatically would be a real pain, I suspect!

  2. There are a few TikZ tricks you can employ to make this a bit easier. First of all, you’re better off using styles, especially if you want to change something.

    The usage of \vphantom is not needed, you can use the options text depth and text height to give every node the same text size, so the arrows will align.

    Finally, there’s an option preaction which you can use to automatically do something on
    the same path before it is actually drawn, combined with a style you can simply say: edge[cross line], for example:

    \begin{tikzpicture}[
            back line/.style={densely dotted},
            normal line/.style={-stealth},
            cross line/.style={normal line,
               preaction={draw=white, -, 
               line width=6pt}},
        ]
        \matrix (m) [matrix of math nodes, 
             row sep=3em, column sep=3em,
             text height=1.5ex, 
             text depth=0.25ex]{
            &amp; f^\ast E_V &amp; &amp; E_V \\
              f^\ast E   &amp; &amp; E   \\
            &amp; U          &amp; &amp; V   \\
              M          &amp; &amp; N   \\
        };
        \path[normal line]
            (m-1-2) edge (m-1-4)
                    edge (m-2-1)
                    edge [back line] (m-3-2)
            (m-1-4) edge (m-3-4)
                    edge (m-2-3)
            (m-2-1) edge [cross line] (m-2-3)
                    edge (m-4-1)
            (m-3-2) edge [back line] (m-3-4)
                    edge [back line] (m-4-1)
            (m-4-1) edge (m-4-3)
            (m-3-4) edge (m-4-3)
            (m-2-3) edge [cross line] (m-4-3);
    \end{tikzpicture}
  3. Hi Berteun,

    thank you for this useful information about the preaction option and the advice concerning styles!

    Stefan

  4. Hallo, with the new update of the package, all arrows seem to disappear, and other than that the letter seem to either shift to some place or all go to the same spot on the pdf output… what should I do?

  5. Hi Sam,

    did it work before? You could downgrade or update to another version, if your current resp. new version is broken, such as a svn version.

    Stefan

Leave a Reply

Required fields are marked *