tikz-cd – Correct Placement of Pullback Corner for Non-Square Rectangular Diagrams

tikz-cd

The recommended way (see Section 4.2 here) to place pullback corners in tikz-cd diagrams is using diagonal phantom arrows, as in

\documentclass{article}
\usepackage{tikz-cd}
\usepackage{amssymb}
\begin{document}
\begin{tikzcd}
    A   \arrow[r] 
        \arrow[d] 
        \arrow[dr, phantom, "\lrcorner", very near start] 
&   B   \arrow[d] 
\\  C   \arrow[r] 
&   D  
\\
\end{tikzcd}
\end{document}

However, this isn't great when the diagram deviates too far from the square shape, eg because of long labels:

\documentclass{article}
\usepackage{tikz-cd}
\usepackage{amssymb}
\begin{document}
\begin{tikzcd}
    A   \arrow[r] 
        \arrow[d] 
        \arrow[dr, phantom, "\lrcorner", very near start] 
&   B   \arrow[d] 
\\  CCCC\arrow[r] 
&   DDDD  
\\
\end{tikzcd}
\end{document}

enter image description here

The problem is that the \lrcorner is further from the left arrow than from the upper arrow.

I can adjust that manually with shift right, but I wonder if there's a method that doesn't place the corner on an invisible diagonal of the rectangle, but rather at a fixed distance at a 45 degree angle from the center of the upper left corner?

This answer seems to do something like this, but with tikzpicture instead of tikzcd, and I don't know how to adapt it to tikzcd.

Best Answer

You can place the \lrcorner symbol as a label for the node. You can set the angle and distance.

enter image description here

\documentclass{article}
\usepackage{tikz-cd}
\usepackage{amssymb}
\begin{document}
\begin{tikzcd}
    |[label={[label distance=-2mm]-45:\lrcorner}]|A   \arrow[r] 
        \arrow[d]  
&   B   \arrow[d] 
\\  CCCC\arrow[r] 
&   DDDD
\end{tikzcd}
\end{document}
Related Question