# Error using tikzmark with multiple tikzcd's

I wish to create a figure like the one shown below.

I am getting the error above with the following code. Can someone tell me where I may be going wrong?

\begin{tikzcd}[arrows={-latex, outer sep=-1.5pt},row sep=1cm, column sep=2cm]
& A \arrow[r, "f"] \arrow[to=F,phantom,"{}\tikzmark{catA}"] & B \arrow[d, "g"] \arrow[rd, "h"'{name=F}]\\
& C
\end{tikzcd}\hspace{2.5cm}
\begin{tikzcd}[arrows={-latex, outer sep=-1.5pt},row sep=1cm, column sep=2cm]
& F(A) \arrow[to=Ff,phantom,"{}\tikzmark{catop}"]  & F(B) \arrow[l, "F(f)"'] \arrow[rd, "h"'{name=Ff}\\
& F(C) \arrow[u, "F(g)"'] \arrow[lu, "F(g \circ f)"]
\end{tikzcd}

\begin{tikzpicture}[remember picture, overlay]
\node[cloudnode1, label={left:$\cat{A}$}](lft) at (pic cs:catA){};
\node[cloudnode1, label={right:$\cat{B}$}](rgt) at (pic cs:catop){};
\draw[-latex, black!80, bend left = 10](lft)to node[above]{F}(rgt);
\end{tikzpicture}

• welcome to TeX.SE. Please, always provide a MWE. The very first error I got adding package tikz-cd was: Package pgf Error: No shape named 'F' is known. I think the culprit is a tikzcd arrow in cell 1-2. It seems you are trying to use "F" before defining it. cloudnode1 also seems to be not defined.
– FHZ
Apr 11 at 23:02
• A more descriptive title for your question will generally get faster assistance. I suggest "Help using tikzmark with tikz-cd" or something like that. Also, always post complete code that starts with \documentclass, includes all relevant \usepackage commands, and ends with \end{document}. Apr 12 at 3:02
• Please, correct the title of your question: Package pgf Error... instead of Package pdf Error.... Apr 12 at 6:07

First, get the commutative diagrams to look the way you want before you mess with tikzmark and clouds:

\begin{tikzcd}[arrows={-latex},row sep=1cm, column sep=1cm]
a \arrow[r, "f"]\arrow[rd, "g\circ f"'] & b \arrow[d, "g"]\\
& c
\end{tikzcd}\hspace{2.5cm}
\begin{tikzcd}[arrows={-latex},row sep=1cm, column sep=1cm]
F(a)   & F(b) \arrow[l, "F(f)"'] \\
& F(c) \arrow[u, "F(g)"'] \arrow[lu, "F(g \circ f)"]
\end{tikzcd}


Then, once those are correct, add a tikzmark in the center of the left diagram. I think a good spot would be along the arrow from a to c, but on the top side. So change the code for the rd arrow to

\arrow[rd, "g\circ f"', "\tikzmark{catA}"]

Now you have a tikzmark named catA that you can use later. To test the position, make a new tikzpicture using \begin{tikzpicture}[remember picture, overlay], which allows you to refer to earlier tikzmarks.

\begin{tikzpicture}[remember picture, overlay]
\node[cloudnode1, label={above:$C$}](lft) at (pic cs:catA){};
\end{tikzpicture}


I am assuming that in your preamble you have defined the style cloudnode1 using code similar to:

\tikzset{cloudnode1/.style={draw, dashed, black!80, inner sep=1cm,
cloud, cloud puffs=10, cloud puff arc=150}}


which I adapted from this earlier answer. By the way, you should always cite other people's work when you post code on this site.

Remember you must compile twice! The result is this:

So far so good. Now you need to do the same thing on the other diagram. Change the lu arrow to:

\arrow[lu, "F(g \circ f)", "\tikzmark{catop}"']

\node[cloudnode1, label={above:$B$}](rgt) at (pic cs:catop){};

to the tikzpicture and...

Looks like the clouds are too small. Increase the inner sep to 1.3cm or whatever looks good to you. Finally, add

\draw[-latex, black!80, bend left = 10, dashed](lft)to node[above]{$F$}(rgt);

and adjust the space between the two clouds. Remember to compile twice!

Here is the complete code:

\documentclass{article}

\usepackage{tikz-cd}
\usetikzlibrary{tikzmark,shapes.symbols}
\tikzset{cloudnode1/.style={draw, dashed, black!80, inner sep=1.3cm, cloud, cloud puffs=10, cloud puff arc=150}}

\begin{document}

\begin{tikzcd}[arrows={-latex},row sep=1cm, column sep=1cm]
a \arrow[r, "f"]\arrow[rd, "g\circ f"', "\tikzmark{catA}"] & b \arrow[d, "g"]\\
& c
\end{tikzcd}\hspace{3cm}
\begin{tikzcd}[arrows={-latex},row sep=1cm, column sep=1cm]
F(a)   & F(b) \arrow[l, "F(f)"'] \\
& F(c) \arrow[u, "F(g)"'] \arrow[lu, "F(g \circ f)", "\tikzmark{catop}"']
\end{tikzcd}

\begin{tikzpicture}[remember picture, overlay]
\node[cloudnode1, label={above:$C$}](lft) at (pic cs:catA){};
\node[cloudnode1, label={above:$B$}](rgt) at (pic cs:catop){};
\draw[-latex, black!80, bend left = 10, dashed](lft)to node[above]{$F$}(rgt);
\end{tikzpicture}

\end{document}


As a final thought, you might want to increase the row sep and column sep on the left diagram so it has the same size as the right one.

\begin{tikzcd}[arrows={-latex},row sep=1.3cm, column sep=1.3cm]

Then the result is:

which looks quite nice to me.