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?

  • 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


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



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



\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[->](G2)--(G2-|B2.north east)to[out=180,in=0](B2.north west);
\draw[->](B2.north west)--(B2.north west-|F2.east);


You must log in to answer this question.

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