1

Using the idea of https://tex.stackexchange.com/a/394924/305075 I use execute at end picture to draw the ellipses in tikz-cd diagrams. The names of the nodes for the ellipse to fit are of the form tikz@f@1-1-1.

The result of the second application of that idea shows that there seems to be a kind of interference between the two diagrams. As if in the second diagram the positions of the nodes of the first are used.

I tried to rename the names to something like tikz@g@1-1-1 (see the g instead of the f) but without success.

My main question, as in the title: How to put ellipses around nodes in tikz-cd diagrams several times in one document?

Second question: can we rename the tikz@f@1-1-1 to tikz@g@1-1-1 where the g is of course just an example?

At the end, I like to draw diagrams of several categories with morphisms and functors. The objects belonging to the same category shall be grouped by putting an ellipse around them. One ellipse per category. The example I have given is much simpler in order to focus on the problem.

I try this:

\documentclass[a4paper]{amsart}

\usepackage{tikz} \usepackage{tikz-cd}

\begin{document} \usetikzlibrary{shapes.geometric,fit} \tikzset{ dashellipse/.style={ellipse,draw,dashed,inner sep=0pt,blue,fit={#1}} }

\begin{equation} \begin{tikzcd}[ name=jk, execute at end picture={ \node[dashellipse=(tikz@f@1-1-1)(tikz@f@1-1-3)]{}; } ] X && Y \end{tikzcd} \end{equation}

\begin{equation} \begin{tikzcd}[ name=mycustommatrix, execute at end picture={ \node[dashellipse=(tikz@f@1-1-1)]{}; } ] X \end{tikzcd} \end{equation}

\end{document}

Two diagrams, second ellipse misplaced

  • 1
    While packages like tikz-cd make it easier to do some things, they make it more difficult or even impossible to do others. For this MWE, it would be easier to use plain tikz. – John Kormylo Sep 29 '23 at 13:05
  • 1
    Why do you need tikzcd; your example does not provide any clue. In case you only need nodes sitting in an ellipse, then you can use the fit library. It was conceived exactly for this job. – Daniel N Sep 30 '23 at 13:00
  • 1
    That’s a good question. At the end I like to draw diagrams of several categories with morphisms and functors. The objects belonging to the same category shall be grouped by putting an ellipse around them. One ellipse per category. The example I have given is much simpler in order to focus on the problem. I will amend the questions accordingly, to provide some motivation. – joergkunze63 Oct 01 '23 at 10:52

1 Answers1

3

Something like this?

enter image description here

With pure tikz picture, using chains, fit and shapes.geometric TikZ libraries:

\documentclass[a4paper]{amsart}
\usepackage{tikz}
\usetikzlibrary{chains,
                fit,
                shapes.geometric}
\tikzset{
node distance = 0mm and 9mm,
  start chain = going right,
     N/.style = {inner sep=1pt, on chain},
    de/.style = {ellipse, draw=blue, densely dashed, inner xsep=-3pt,
                 fit={#1}, node contents={}},
every picture/.append style = baseline=(current bounding box.base)
            }

\begin{document}

\begin{equation} \begin{tikzpicture} \node (n1) [N] {A}; \node (n2) [N] {B}; \node[de=(n1) (n2)]; \end{tikzpicture} \end{equation}

\begin{equation} \begin{tikzpicture} \foreach \i [count=\j] in {C, , D} \node (n\j) [N] {\i};
\node[de=(n1) (n3)]; \end{tikzpicture} \end{equation}

\begin{equation} \begin{tikzpicture} \foreach \i [count=\j] in {C, D, E, F, G} \node (n\j) [N] {\i}; \node[de=(n1) (n3)]; \node[de=(n4) (n5)]; \end{tikzpicture} \end{equation}

\begin{equation} \begin{tikzpicture} \node (n1) {X}; \node[de=(n1)]; \end{tikzpicture} \end{equation}

\end{document}

Zarko
  • 296,517