# Node positions in Tikzpicture for using tikzmark

I wish to create a diagram like this.

My attempt is shown below: Output

Code

\documentclass{article}

\usepackage{tikz-cd}
\usetikzlibrary{tikzmark,shapes.geometric,shapes.symbols}
\tikzset{elnode/.style={draw, ellipse, dotted, minimum height=1cm, label distance=-2mm},
cloudnode/.style={draw, dotted, black!80, inner sep=1.75cm, cloud, cloud puffs=20, cloud puff arc=100}}

\begin{document}

\begin{tikzpicture}
\subnode{A}{ptA} at (0, 0);
\end{tikzpicture} \hspace{5cm}

\begin{tikzcd}[arrows={-latex, outer sep=-1.5pt},row sep=2cm, column sep=2cm]
& \subnode{ptfa}{F(A)} \arrow[d, "\alpha_A"{name = arrow1}] \arrow[to=arrow1, phantom, "{}\tikzmark{Fa}"]\\ & \subnode{ptga}{G(A)}
\end{tikzcd}

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

\end{document}


I would like to know how I can add space between the two cloudnodes. hspace{} doesn't seem to work.

I am new to Latex. I'd like to mention the previous help that I have received so far. @user:125871 (SandyG) has been very helpful. They have helped me make some progress so far. This is the first question that I posted: https://tex.stackexchange.com/a/640262/268068

• Your code does not compile. Always provide a "Minimal Working Example" (MWE) that starts with \documentclass, includes all relevant \usepackage commands, ends with \end{document} and compiles without errors, even if it does not produce your desired output. Apr 14 at 19:31
• @SandyG Sorry about that. I have edited the code to include document class. Any help will be much appreciated! Apr 14 at 20:01
• @SandyG I made some progress. Now all I need to know is 1. how to add space. \hspace{} doesn't seem to be working, and 2. I'd like to move the second cloud on the right a bit upwards vertically. Thank you! Apr 14 at 20:11
• The hspace doesn't work because the blank line after it creates a new line, so you need to remove that blank line to put the two pictures on a level. \subnode is meant to be used inside a \node, not by itself. It works in the tikzcd because things get put inside nodes automatically but it can't be used in a tikzpicture as you use it. When you say that you want to keep the style of your picture, what do you want to keep? In trying to fix your code then there are many things I would do differently, so knowing what is essential is useful. Apr 14 at 21:36

I'm not sure why your code is so complicated, as I think this can be done with some simple tools. This is what I got following the diagram you are looking to replicate:

\documentclass{article}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
\draw (0,0) circle (1) node(a){A};
\node[draw,circle,right of=a, node distance=4cm, inner sep=1cm](two){};
\node[above of=two](up){F(A)};
\node[below of=two](down){G(A)};
\draw (up) edge[->] node[anchor=west]{f} (down);
\draw[dotted] (0.2,0.2) .. controls (2,1) and (3,1) .. (3.5,1);
\draw[dotted,label={right:f}] (0.2,-0.2) .. controls (2,-1) and (3,-1) .. (3.5,-1);
\end{tikzpicture}

\end{document}

• Thank you! I am using that format because all the other pictures which are complicated use that format in my paper. I wish to keep it visually consistent. Apr 14 at 20:23
• @concordepi No problem. If this is what you were looking for, check mark the answer for future reference. If not, I'm not familiar with the formatting you were using in your own formatting so I hope someone else can help! Apr 14 at 20:25

I think that it is easier to construct diagrams such as this in a single tikzpicture environment rather than as pieces. It is possible to use the tikz-cd styles in a tikzpicture (see section 3.3 in the manual).

\documentclass{article}
%\url{https://tex.stackexchange.com/q/640820/86}
\usepackage{tikz-cd}
\usetikzlibrary{
shapes.geometric,
shapes.symbols,
positioning,
fit
}
\tikzset{
elnode/.style={
draw,
ellipse,
dotted,
minimum height=1cm,
label distance=-2mm
},
cloudnode/.style={
draw,
dotted,
black!80,
inner sep=1.75cm,
cloud,
cloud puffs=20,
cloud puff arc=100}
}

\newcommand\cat[1]{\mathcal{#1}}

\begin{document}

\begin{tikzpicture}[commutative diagrams/every diagram]
\matrix[
matrix of math nodes,
name=m,
row sep=2cm,
commutative diagrams/every cell,
] {
F(A) \\
G(A) \\
};

\path[
commutative diagrams/.cd,
every arrow,
every label
]
(m-1-1) edge node {$$\alpha_A$$} (m-2-1);

\node[
cloudnode,
fit=(m),
inner sep=0pt,
label={above: $$\cat{B}$$}
] (B) {};

\node[
cloudnode,
left=2cm of B,
label={above: $$\cat{A}$$}
] (A) {};

\draw[
-latex,
dotted,
black!80,
bend right
]
(A.center) to node[auto,swap] {$$F$$} (m-1-1);

\draw[
-latex,
dotted,
black!80,
bend right
]
(A.center) to node[auto,swap] {$$G$$} (m-2-1);

\end{tikzpicture}

\end{document}


• It is not entirely clear, what you after:
• reproduce showed image
• correct your MWE (which result is different from provided sketch)
• make suggestion which combine both?
• Your MWE is unnecessary complicated. Much simpler is to draw in single trikzpicture environment:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
fit,
positioning,
quotes,
shapes.symbols}

\begin{document}
\begin{tikzpicture}[
node distance = 6mm and 36mm,
> = {Stealth[scale=2]},
arr/.style = {->, densely dashed},
cn/.style = {cloud, cloud puffs=12,
draw, thick, dotted,
inner sep=#1},
]
\node (A)   {$A$};
\node (F) [above right=of A]  {$F(A)$};
\node (G) [below right=of A]  {$G(A)$};
%
\node [cn=12pt, fit=(A),
label=$\mathcal{A}$] {};
\node [cn= 6pt, fit=(F) (G),
label=$\mathcal{B}$] {};
%
\draw[arr]  (A) edge [bend right, "$F$"  ]  (F)
edge [bend right, "$G$" ']  (G);
\draw[->]   (F) edge ["$\alpha A$"] (G);
\end{tikzpicture}
\end{document}