TikZ: Commutative diagrams with crossing edges
7 January 2009 by Stefan Kottwitz
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:

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.
This entry was posted on 7 January 2009 at 10:01 PM and is filed under pgf/TikZ, Mathematics. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.




8 January 2009 at 10:12 AM
Nice trick. Doing this kind of thing automatically would be a real pain, I suspect!
13 January 2009 at 5:44 PM
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:
15 January 2009 at 11:12 AM
Hi Berteun,
thank you for this useful information about the preaction option and the advice concerning styles!
Stefan