# How do you draw a commutative diagram inside another commutative diagram in tikz?

I have this commutative diagram to draw :

I have no idea how to get the inner diagram to properly display and not mess with the whole thing. I can get the outer one but as soon as I do anything to try and add the extra arrow and all, I get plenty of errors, and the diagram looks nothing like the picture above (done in geogebra). I'd be grateful if anyone could help out ! Also, I have a less important issue, but is it possible to scale the diagram ? The command \begin{tikzcd}[scale=2] doesn't seem to do anything, and the environnement \scalebox{2}{...} produces errors and doesn't scale anything either. Thanks.

• Welcome to TeX.SE! Your post is far too vague for us to help you. What errors do you get? What exactly is your output, if you're getting any? It's impossible to answer you if we don't know what's wrong. – dgoodmaniii Nov 25 '19 at 18:32

You can just use one diagram for that. (Note that solution adding boxes od width 0 may screw up the bounding box.)

\documentclass{article}
\usepackage{tikz-cd}
\begin{document}
\begin{tikzcd}[every arrow/.append style={thick,-stealth},
execute at end picture={
\node[right=-4pt,fill=white,baseline={(aBf.base)}] at (aBf.east){$=\{a'\in\mathcal{B}\mid f(a')=b\}$};}
]
A \arrow[rrrr,"f"]  \arrow[dddrr,"\pi_{\mathcal{B}_f}"'] & & & & B \\[-1em]
& a \arrow[rr] \arrow[dr] & & b & \\[2ex]
&& |[alias=aBf]|[a]_{\mathcal{B}_f} \arrow[ur] && \\
&& \mathcal{B}_f \arrow[uuurr,"\bar f"' {pos=0.85}] && \\
\end{tikzcd}
\end{document}


Or a smaller version thereof.

\documentclass{article}
\usepackage{tikz-cd}
\begin{document}
\begin{tikzcd}[every arrow/.append style={thick,-stealth},column sep=small,
row sep=small,
execute at end picture={
\node[right=-4pt,fill=white,baseline={(aBf.base)}] at (aBf.east){$=\{a'\in\mathcal{B}\mid f(a')=b\}$};}
]
A \arrow[rrrr,"f"]  \arrow[dddrr,"\pi_{\mathcal{B}_f}"'] & & & & B \\[-1em]
& a \arrow[rr] \arrow[dr] & & b & \\[2ex]
&& |[alias=aBf]|[a]_{\mathcal{B}_f} \arrow[ur] && \\
&& \mathcal{B}_f \arrow[uuurr,"\bar f"' {pos=0.85}] && \\
\end{tikzcd}
\end{document}


• Thanks that's great ! I'm not sure what some of this is and what it does but I'll look it up (ex: the first three lines after \begin{tikzcd} or the [alias=aBf]). – not an analyst Nov 25 '19 at 18:42
• @Tommy This i a trick to add the text starting from the = sign in =\{a'\in\mathcal{B}\mid f(a')=b\} without making the corresponding node wider. One may be tempted to use a \mathllap for that but this has several problems, including destroying the bounding box. So I add this node after the commutative diagram is done. alias is just a way to give the node another identifier. – user194703 Nov 25 '19 at 18:45
• Thanks a lot, that helped ! – not an analyst Nov 25 '19 at 19:16