# Shorten some horizontals with tikz-cd

The following tikz-cd code produces the diagram:

\documentclass[tikz]{standalone}
\usepackage{tikz-cd}

\begin{document}

\begin{tikzcd}
A & B \arrow[r] \arrow[d] & C \arrow[d] \\
D& E \arrow[r] &F
\end{tikzcd}

\end{document}


How, if at all, is it possible to move the A and D closer to B and E, respectively (while still keeping them horizontally and vertically aligned, of course)?

After greatly revising my question to the one above, I discovered at Length of arrow in tikz-cd the use of optional parameter to & to change the spacing of columns. And egreg's answer shows just that.

• Sorry for changing my question so much so quickly. The preferred answers do answer my original question; egret's also answers my emended question. Commented Sep 17, 2016 at 21:00

Think to the diagram as a matrix: we have two rows and three columns; so in each row we need two & characters. In each cell add the arrows starting from it, with their target.

\begin{tikzcd}
A \arrow[r] \arrow[d] & B \arrow[r] \arrow[d] & C \arrow[d] \\
D \arrow[r] & E \arrow[r] & F
\end{tikzcd}


If the diagram is more complicated, it's not really different. For instance, suppose we have A on the top row with arrows pointing to B, C and D on the bottom row, with A above B; we also want an arrow from B to C and one from C to D.

\begin{tikzcd}
A \arrow[d,"f"] \arrow[rd,"g"] \arrow[rrd,"h"] \\
B \arrow[r,"\beta"] & C \arrow[r,"\gamma"] & D
\end{tikzcd}


Oh, wait! The second diagram is very bad!

We get a better one by spacing more the columns and by changing the positions of the labels:

\begin{tikzcd}[column sep=4em]
A \arrow[d,swap,"f"] \arrow[rd,swap,"g"] \arrow[rrd,"h"] \\
B \arrow[r,swap,"\beta"] & C \arrow[r,swap,"\gamma"] & D
\end{tikzcd}


Better yet: make it more symmetric:

\begin{tikzcd}[column sep=4em]
& A \arrow[dl,swap,"f"] \arrow[d,swap,"g"] \arrow[rd,"h"] \\
B \arrow[r,swap,"\beta"] & C \arrow[r,swap,"\gamma"] & D
\end{tikzcd}


For shortening the distance between two columns, use the optional parameter to &:

\begin{tikzcd}
A &[-2em] B \arrow[r] \arrow[d] & C \arrow[d] \\
D & E \arrow[r] & F
\end{tikzcd}


• Is it possible to accomplish the same thing as in the final image (with no arrows from/to A or D and closer horizontal spacing to their right) by means of phantom arrows? That's what I tried first, to no avail. Commented Sep 17, 2016 at 21:09
• @murray What phantom arrows? Besides, use a method that works. ;-) Commented Sep 17, 2016 at 21:11
• OK. And is it possible to use something like \text{Top} in place of A for a node? (I tried but get "undefined control sequence error.) Commented Sep 17, 2016 at 21:18
• It certainly would have helped if the tikz-cd documentation had said something like the 1st paragraph of your answer! (Perhaps it should have been obvious, but it wasn't to me.) Commented Sep 17, 2016 at 21:27
• @murray \text requires amsmath. About why the analogy with matrices is not spelled out, I can only assume that the author thought everybody was aware of it. Commented Sep 17, 2016 at 21:41

You can make such a diagram either with tikz-cd or with pstricks, more specifically with the the psmatrix environment from pst-node:

\documentclass[pdf]{article}
\usepackage{tikz-cd}
\usepackage{pst-node,  multido, auto-pst-pdf}

\begin{document}

$\begin{tikzcd} A\dar \rar [dashed] & B\dar\rar [dashed] & C\dar\\% D \rar [dashed] & E \rar [dashed] & F \end{tikzcd}$

$\def\pscolhookii{\hskip-.4cm} \begin{psmatrix}[colsep=1.2cm, rowsep=0.8cm] %% nodes A & B & C\\ D & E & F %%arrows \psset{arrows=->, arrowinset=0.15, nodesep=3pt, linewidth=0.6pt} \ncline{1,1}{2,1} \ncline{1,2}{2,2} \ncline{1,3}{2,3} \psset{ linestyle=dashed, dash=3pt 2pt} \ncline{1,1}{1,2} \ncline{1,2}{1,3} \ncline{2,1}{2,2} \ncline{2,2}{2,3} \psset{ linestyle =dash} \end{psmatrix}%$ %

\end{document}


Added: For your new requirement, I know how to do that with pstricks, and I've updated my code accordingly.