%&latex
\documentclass[11pt]{article}
\usepackage[margin=1in]{geometry}
\usepackage{tikz}
\usetikzlibrary{cd}
\usepackage{amsbsy}
\begin{document}
\section{The basics of styling commutative diagrams}
Here are two ways to make the same square diagram:
\[
\begin{tikzcd}
A\ar[r]\ar[d] & B\ar[d]\\
C\ar[r] & D
\end{tikzcd}
\begin{tikzcd}
A & B\\
C & D
\arrow[from=1-1,to=1-2]
\arrow[from=1-1,to=2-1]
\arrow[from=2-1,to=2-2]
\arrow[from=1-2,to=2-2]
\end{tikzcd}
\]
The second of these is more clunky, since it requires the use of absolute coordinates, rather than the relative coordinates used in the first example. However, it is essential to use the latter of these when the order in which you define the arrows matters. The most common example of this is when a diagram has overlapping arrows, which will be shown now.
\subsection{Fixing overlapping arrows}
Consider the following commutative cube diagram:
\[
\begin{tikzcd}
& {A'}\ar[rr]\ar[dd] && {B'}\ar[dd] \\
A\ar[ur]\ar[rr]\ar[dd] && B\ar[ur]\ar[dd] \\
& {C'}\ar[rr] && {D'} \\
C\ar[ur]\ar[rr] && D\ar[ur]
\end{tikzcd}
\]
This looks terrible. Luckily, Ti\(k\)Z has us covered, with the ``crossing over" command.
\[
\begin{tikzcd}
& {A'}\ar[rr]\ar[dd] && {B'}\ar[dd] \\
A\ar[ur]\ar[rr, crossing over]\ar[dd]
&& B\ar[ur]\ar[dd, crossing over] \\
& {C'}\ar[rr] && {D'} \\
C\ar[ur]\ar[rr] && D\ar[ur]
\end{tikzcd}
\]
Uh-oh! It seems that the command didn't work for the arrow \(B\to D\). Luckily, this is easily remedied, using the aforementioned absolute coordinates.
This issue occurs because the arrow \(C'\to D'\) is defined \emph{after} the arrow \(B\to D\). But we can easily fix this, by defining our arrow \(B\to D\) after everything else, like so:
\[
\begin{tikzcd}
& {A'}\ar[rr]\ar[dd] && {B'}\ar[dd] \\
A\ar[ur]\ar[rr, crossing over]\ar[dd]
&& B\ar[ur] \\
& {C'}\ar[rr] && {D'} \\
C\ar[ur]\ar[rr] && D\ar[ur]
\ar[from=2-3, crossing over]
\end{tikzcd}
\]
This is much better. I generally recommend defining entire diagrams using the relative coordinates, then when things break due to the order in which arrows are defined, remedy the specific arrows which need to be on top. However, if your diagram is particularly complicated, this will be insufficient, and I instead recommend a little bit more careful planning of your arrow definitions.
\subsection{The shape of the grid}
Notice that in the na\"ive definition of a commutative square diagram, the diagram is not a square:
\[
\begin{tikzcd}
A\ar[r]\ar[d] & B\ar[d]\\
C\ar[r] & D
\end{tikzcd}
\]
Rather, the width is slightly larger than the height. There is a remedy: use the PGFkeys option ``between origins" for both the column sep and row sep values (I recommend doing this anyway to avoid some issues with cells having varying width entries), and set their values to be the same specified constant:
\[
\begin{tikzcd}[column sep={30, between origins}, row sep={30, between origins}]
A\ar[r]\ar[d] & B\ar[d]\\
C\ar[r] & D
\end{tikzcd}
\]
I think 30 is quite nice, unless your maps have long names. With this, your commutative ``squares" can actually be squares. Note that this takes up more vertical space on the page, which may be a bad thing if there is some worry about a page count restriction.
The same principle can be used to fundamentally change how your diagrams are sructured. Here is an example using the settings I recommend for making a diagram with a hexagonal grid:
\[
\begin{tikzcd}[column sep={20, between origins}, row sep={20*1.75, between origins}]
&A\ar[rr]\ar[rd]\ar[dl] && B\ar[ld]\ar[dr]\\
C\ar[rr]\ar[dr] && D\ar[rr]\ar[dl]\ar[dr] && E\ar[dl]\\
&F\ar[rr] && G
\end{tikzcd}
\]
The choice of 1.75 as a multiplier for the row sep is because it's roughly equal to \(\sqrt{3}\approx 1.7320508\), and choosing a more accurate value doesn't make the diagram any more or less pleasing to the eye in my opinion.
The last thing I will mention about the shape of the grid is the ability to manually change the perspective angle of 3D diagrams. Recall again the following cube:
\[
\begin{tikzcd}
& {A'}\ar[rr]\ar[dd] && {B'}\ar[dd] \\
A\ar[ur]\ar[rr, crossing over]\ar[dd]
&& B\ar[ur] \\
& {C'}\ar[rr] && {D'} \\
C\ar[ur]\ar[rr] && D\ar[ur]
\ar[from=2-3, crossing over]
\end{tikzcd}
\]
We are viewing this cube from a particular angle, which can be changed by cleverly adjusting the distance between specified rows/columns by a fixed amount. First, let's make the same adjustments to column sep and row sep as before:
\[
\begin{tikzcd}[column sep={25, between origins}, row sep={25, between origins}]
& {A'}\ar[rr]\ar[dd] && {B'}\ar[dd] \\
A\ar[ur]\ar[rr, crossing over]\ar[dd]
&& B\ar[ur] \\
& {C'}\ar[rr] && {D'} \\
C\ar[ur]\ar[rr] && D\ar[ur]
\ar[from=2-3, crossing over]
\end{tikzcd}
\]
Already, this is more cube-like. Now, let's define a new length, which will encode the amount by which we are changing our viewing angle.
\newlength{\perspective}
\setlength{\perspective}{10}
Using this new length variable, let's shift our perspective:
\[
\begin{tikzcd}[column sep={25, between origins}, row sep={25, between origins}]
&[\perspective] {A'}\ar[rr]\ar[dd] &[-\perspective]&[\perspective] {B'}\ar[dd] \\[-\perspective]
A\ar[ur]\ar[rr, crossing over]\ar[dd]
&& B\ar[ur] \\[\perspective]
& {C'}\ar[rr] && {D'} \\[-\perspective]
C\ar[ur]\ar[rr] && D\ar[ur]
\ar[from=2-3, crossing over]
\end{tikzcd}
\]
Cube successfully rotated. I recommend changing the value for the perspective variable above, and seeing how the second cube changes.
Rotating the cube in other ways requires some more careful handling of the diagram. For example, to rotate about the ``vertical" axis of the diagram, the horizontal arrows cannot be contained entirely within the same row, therefore the positions of cells must be changed to accomodate such a rotation.
\end{document}