# How to do pullback with universal property diagram?

I want to make a commutative diagram in the tikz (or tikz-cd) environment to demonstrate the universal property of the pullback. To be precise, I want to make the following diagram in LaTeX (the arrows on top need NOT be curved):

I am not sure how to draw this. I know how to make general commutative diagrams, and there are answers to making pushouts with universal property diagrams (How to do the pushout with universal property?) but I can't figure out how to make the above pullback diagram. Any help will be appreciated.

• Welcome! What can you do? You are much more likely to get help if you provide a minimal compilable document people can work with and explain precisely where you get stuck.
– cfr
Commented Nov 3, 2023 at 17:02
• Thank you very much for all the insightful answers :) Commented Nov 4, 2023 at 22:37

You have to think to a 3x3 matrix and the rest follows.

In the top left corner you place B and the other items in the 2x2 bottom right corner. Thus the skeleton is

\begin{tikzcd}
B \\
& Q & A \\
& B & C
\end{tikzcd}


Now you want to add the arrows. There are three of them starting from the top left corner and the others are easy to add.

\begin{tikzcd}
B \arrow[ddr] \arrow[drr] \arrow[dr,dashed] \\
& Q \arrow[r] \arrow[d] & A \arrow[d] \\
& B \arrow[r] & C
\end{tikzcd}


Now we want to add the labels

\begin{tikzcd}
B \arrow[ddr,"\mathrm{Id}"] \arrow[drr,"h"] \arrow[dr,dashed,"\beta"] \\
& Q \arrow[r,"q"] \arrow[d,"g^*"] & A \arrow[d,"f"] \\
& B \arrow[r,"g"] & C
\end{tikzcd}


OK, now we clearly see that bending the outer arrows is really necessary. Also the “Id” label should go on the opposite side and the "g*" label should be moved slightly higher, which can be accomplished by smashing the bottom of the "Q”.

\begin{tikzcd}
B \arrow[ddr,bend right,"\mathrm{Id}"'] \arrow[drr,bend left,"h"] \arrow[dr,dashed,"\beta"] \\
& \smash[b]{Q} \arrow[r,"q"] \arrow[d,"g^*"] & A \arrow[d,"f"] \\
& B \arrow[r,"g"] & C
\end{tikzcd}


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

\begin{tikzcd}
B \arrow[rrd,bend left,"h"]
\arrow[ddr,bend right,swap,"\mathrm{Id}"]
\arrow[dr,dashed,"\beta"] \\
& Q \arrow[d,"g^*"'] \arrow[r,"q"] & A \arrow[d,"k"]  \\
& B \arrow[r,swap,"g"]  & C
\end{tikzcd}

\end{document}


I use xy package with the function cmtip i.e. with the same tips of the arrows of TiKZ. Here can you see the differences with tikz-cd code. The xy code is similar to that of tikz-cd.

\documentclass[a4paper,12pt]{article}
\usepackage{amsmath,amssymb}
\usepackage[all,cmtip]{xy}
\begin{document}
\xymatrix{
B \ar@/_1.5pc/[ddr]_{\mathrm{Id}} \ar@/^1.5pc/[drr]^h
\ar@{-->}[dr]^\beta \\
& Q \ar[d]_{g^{*}} \ar[r]^q
& A \ar[d]^k \\
& B \ar[r]_g & C}
\end{document}