# tikz-cd: draw commutative square as an actual square

What is the easiest way to adjust the following commutative square so that the arrows are all at an angle of approximately 45 degrees (two pointing north east, two pointing south east)? Naively, I imagine the nodes centred on a grid,and then the arrows drawn relative to the positions of the nodes on the grid, ignoring the size of the text.

I would like the solution to be based on tikz-cd. Hard-coded widths are fine.

\documentclass{article}
\usepackage{tikz-cd}

\begin{document}
\begin{tikzcd}
& P \mid z(y).Q \arrow[dr, "z(y)"] \\
(x(y).P) \mid z(y).Q
\arrow[ur, "x(y)"] \arrow[dr, "z(y)"'] & & P' \\
& (x(y).P) \mid Q \arrow[ur, "x(y)"']
\end{tikzcd}
\end{document}


I experimented with a couple of the simpler solutions described here, without much success:

Tikz-cd: How can I arrange diagonal arrows parallel?

How to ensure consecutive diagonal arrows form a straight line?

You had two missing & symbols. I guess, this is the reason why the most obvious solution (see below) did not work for you.

\documentclass{article}
\usepackage{tikz-cd}

\begin{document}
\begin{tikzcd}[column sep={3cm,between origins},row sep={3cm,between origins}]
& P \mid z(y).Q \arrow[dr, "z(y)"] & \\ % <= here
(x(y).P) \mid z(y).Q
\arrow[ur, "x(y)"] \arrow[dr, "z(y)"'] & & P' \\
& (x(y).P) \mid Q \arrow[ur, "x(y)"'] &  % <= here
\end{tikzcd}
\end{document}


This is exact and not "approximately 45 degrees"

Update:

The OP asked to explain the between origins parameter a bit.

The normal method for tikz-cd is to set the distance between the cells. If you have one single cell with a lot of text, this very column will appear very wide as the distance (separator) to the left and right column will stay the same. If you want to have each column the same width (rows resp. of course), you can set the distance between the centres of your cells. In this case, it does not matter how much a cell contains, the columns will keep the same width.

I try to explain it graphically:

% arara: lualatex

\documentclass{article}
\usepackage{tikz-cd}
\usepackage{lua-visual-debug}

\begin{document}
\begin{tikzcd}[column sep={1cm,between origins},row sep={1cm,between origins}]
A & B\\
C & D
\end{tikzcd}
\begin{tikzcd}[column sep={1cm},row sep={1cm}]
A & B\\
C & D
\end{tikzcd}

\begin{tikzcd}[column sep={1cm,between origins},row sep={1cm,between origins}]
AAAAAA & B\\
C & D
\end{tikzcd}
\begin{tikzcd}[column sep={1cm},row sep={1cm}]
AAAAAA & B\\
C & D
\end{tikzcd}
\end{document}


• Perfect! Yes, I did try playing with column sep. Thanks. (Also you beat me to your typo :)
– Roly
Jul 24, 2015 at 7:47
• Not "too" great? I think you're pretty good ;)
– Roly
Jul 24, 2015 at 7:51
• Btw, would you mind briefly explaining between origins?
– Roly
Jul 24, 2015 at 7:53
• @Roly see my update. Jul 24, 2015 at 8:01
• I had problems with "column sep={10em, between origins}" (note the space before "between") and got the not very enlightening error message "! Package PGF Math Error: Unknown function `between' (in ' between origins')." Replacing it with "column sep={10em,between origins}" (without the space) solved the problem. In this answer this space does not appear. I am just writing this for the case that someone else runs into the same problem. Feb 8, 2017 at 19:10