I sometimes find myself typesetting commutative cubes using TikZ. Here is my code.
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}
\tikzset
{
over/.style={preaction={draw=white,-,line width=6pt}},
}
\begin{document}
\begin{tikzpicture}
\matrix[matrix of math nodes,column sep={2.5em},row sep={2.5em},
text height=1.5ex,text depth=.25ex]
{
|(e)| X X X X & & |(0)| X_0 \\
& |(1)| X_1 & & |(01)| X_{01} \\
|(2)| X_2 & & |(02)| X_{02} \\
& |(12)| X_{12} & & |(012)| X_{012} \\
};
\draw[->] (e) to (2);
\draw[->] (0) to (02);
\draw[->] (e) to (0);
\draw[->] (2) to (02);
\draw[->,over] (1) to (12);
\draw[->] (01) to (012);
\draw[->,over] (1) to (01);
\draw[->] (12) to (012);
\draw[->] (e) to (1);
\draw[->] (0) to (01);
\draw[->] (2) to (12);
\draw[->] (02) to (012);
\end{tikzpicture}
\end{document}
The problem that I often encounter is that if one of the nodes is larger than the others, then my cube is a little distorted.
My ad hoc fix is to adjust the width of one of the colums, for example by changing the first line in the matrix to
|(e)| X X X X & & |(0)| X_0 &[1em] \\
Then the result is pretty good:
Another thing I tried is changing the column sep and row sep options to:
column sep={5em,between origins},row sep={5em,between origins}
but then the edges are still not quite parallel:
I'm quite satisfied with the look of the second picture, but this method has a disadvantage that I have to guess a good offset value which is usually cumbersome. Is there a way of making TikZ figure out this value on its own? Or maybe there is a better way of using between origins or something else entirely?






12if you write 12.120 TikZ wil think that this is a number and you will spend lots of time thinking what might be the problem. Hence, don't do numbers in node names. – percusse Sep 14 '16 at 13:02