I wish to draw a picture like this with an arbitrary shape around a few points with arrows between them. I am using the circle command in tikzpicture but the result is very different. Could someone guide me?
1 Answer
This is a job for ... tikzmark
!
Basic idea: make your tikzcd
as usual. But place a tikzmark
in the middle. I placed one on an invisible (phantom
) arrow from a
to f
and called it middleL
.
Then leave some space and make your tikzpicture
as usual. But place a tikzmark
in the middle. I put one at (0,0)
and called it middleR
.
Then start a new tikzpicture
using \begin{tikzpicture}[remember picture, overlay]
. Draw big puffy cloud nodes (using shapes.symbols
) and place them at coordinates using the syntax (pic cs:middleL)
and (pic cs:middleR)
(which is how to refer to previous tikzmark
s). Then just treat them like ordinary nodes—label
them and \draw
an arrow between them with bend left
.
Note: You must compile twice when using tikzmark.
Here is the 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, dashed, black!80, inner sep=1.75cm, cloud, cloud puffs=20, cloud puff arc=120}}
\begin{document}
\begin{tikzcd}[arrows={-latex, outer sep=-1.5pt},row sep=1cm, column sep=2cm]
& b\arrow[dd,bend left=20,"f"{name=F}]\\
a\arrow[ur,bend left,"g_1"]\arrow[ur,"g_2"]\arrow[ur,bend right,"g_3"]
\arrow[dr,bend left=20,"h_1"']\arrow[dr,bend right=20,"h_2"']
\arrow[to=F,phantom,"{}\tikzmark{middleL}"] \\
& c
\end{tikzcd}\hspace{3.5cm}
\begin{tikzpicture}[baseline,font=\small]
\node[elnode,label={above:$C(a,b)$}] at(0,1){$g_1\quad g_2\quad g_3$};
\node[elnode,label={below:$C(a,c)$}] at (0,-1){$h_1\quad h_2$};
\node at (0,0){\tikzmark{middleR}{}};
\end{tikzpicture}
\begin{tikzpicture}[remember picture, overlay]
\node[cloudnode, label={above:$C$}](lft) at (pic cs:middleL){};
\node[cloudnode, label={above:\textbf{Set}}](rgt) at (pic cs:middleR){};
\draw[-latex](lft)to[bend left]node[above]{$C(a,-)$}(rgt);
\end{tikzpicture}
\end{document}
-
And incidently, you managed to do all the work for OP, that's very nice of you ;)– SebGlavApr 10, 2022 at 9:08
-
Thanks a lot! Follow up question: how to ensure that each of the diagrams gets a cloud? When I write a similar code for a few diagrams on the same page, only the last one gets the clouds when typeset. Apr 10, 2022 at 10:17
-
@concordepi: Did you give each
tikzmark
a different name? Did you try compiling again? If those aren't the issues you may want to post a new question with your code. Please remember, on this site you should always post a complete MWE. You will rarely get help if you just post a picture and ask for assistance without providing your code. You can also reference this earlier question when you post your new one.– Sandy GApr 10, 2022 at 17:30
\documentclass
, includes all relevant\usepackage
commands, ends with\end{document}
and compiles without errors, even if it does not produce your desired output.