0

enter image description here

I can't seem to find a general tikz-cd outline for creating the above diagram. My use case is for parametric lenses in category theory, but I can't seem to find any code even close to the above diagram. Can anyone help with providing code using the tikz-cd package which produces the above diagram?

1
  • This “string diagrams” are not possible with tikz-cd. Maybe a starting point is in this question Commented Apr 22, 2022 at 23:49

1 Answer 1

3

This is definitely easier to do with pure TikZ instead of tikz-cd. The node layout isn't hard with tikz-cd, but the line shapes, specifically the splitting, curved paths, are quite difficult. Much easier with Tikz.

The basic idea is to place your nodes and then draw the lines between them. Play around with the positioning until it looks the way you want. I made two styles of nodes (big box and small box). Many adjustments are possible.

enter image description here

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{positioning}

\tikzset{big box/.style={draw, minimum width=5cm, minimum height=4cm},
    small box/.style={draw, minimum width=1cm, minimum height=1cm}}

\begin{document}

\begin{tikzpicture}

\node[big box] at (0,0)(F){};
\node[right=of F](M){};
\node[above=of M.center, anchor=center](B1){$B$};
\node[below=of M.center, anchor=center, yshift=-.5cm](B2){$B'$};
\node[big box, right=of M] (G){};
\node[small box, above=of F.center, anchor=center](F1){$f$};
\node[small box, below=of F.center, anchor=center](F2){$f^*$};
\node[small box, above=of G.center, anchor=center](G1){$g$};
\node[small box, below=of G.center, anchor=center](G2){$g^*$};
\node[left=of F.west, yshift=.5cm](A1){$A$};
\node[left=of F.west, yshift=-1cm](A2){$A'$};
\node[right=of G.east, yshift=1cm](C1){$C$};
\node[right=of G.east, yshift=-1.25cm](C2){$C'$};
%
\draw[->](C2)--(C2-|G2.east);
\draw[->](G2)--(G2-|B2.north east)to[out=180,in=0](B2.north west);
\draw[->](B2.north west)--(B2.north west-|F2.east);
\draw[->](F2)--(A2);
\draw[->](A1)--++(2,0)to[out=0,in=180]++(1,.5)--(F1);
\draw[->](A1)--++(2,0)to[out=0,in=180]++(1,-.5)--(F.center);
\draw[->](F.center)--++(1,0)arc(90:-90:.4)node(T){}--(T-|F2.east);
\draw[->](F1)--++(3,0)node(T2){};
\draw[->](T2.center)to[out=0,in=180]++(1,-.5)--++(1,0)node(T3){}to[out=0,in=180]++(1,.5)--(G1);
\draw[->](T3){}to[out=0,in=180]++(1,-.5)--(G.center)--++(1,0)arc(90:-90:.4)node(T4){}--(T4-|G2.east);
\draw[->](G1)--(C1);
\end{tikzpicture}

\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .