# Circling a collection objects in xymatrix

I have the following code that produces a bicomplex:

\begin{displaymath}
\xymatrix{
0 \ar[r] & \Omega^0_X \ar[d] \ar[r] & \Omega_X^1 \ar[r] \ar[d] & \ldots \ar[r] & \Omega_X^n \ar[d] \ar[r] & 0 \\
0 \ar[r] & C^0(\Omega^0_X) \ar[d] \ar[r] & C^0(\Omega_X^1) \ar[r] \ar[d] & \ldots \ar[r] & C^0(\Omega_X^n) \ar[d] \ar[r] & 0 \\
0 \ar[r] & C^1(\Omega^0_X) \ar[d] \ar[r] & C^1(\Omega_X^1) \ar[r] \ar[d] & \ldots \ar[r] & C^1(\Omega_X^n) \ar[d] \ar[r] & 0 \\
&   \vdots                       & \vdots                        & \ldots        & \vdots                        & \\
}\end{displaymath}


which produces

I would like to circle each of the diagonals, in the bottom left to top right direction. I have resolved to (and am currently) working my way through the XYpic manual, but as is often the case, it is probably too late.

So my question is, is it possible to circle (though I guess it will be more of an ellipse) the elements as described, either in xymatrix/xypic, or in Tikz (though I know very little Tikz)? See picture below for a poorly drawn version:

I have found the ellipse command in an XYpic reference manual, but I am not familiar enough with the surrounding code to make use of it. Moreover, I am not sure if basic XYpic code can be put in to xymatrix. Clarification on either point would be very helpful as a partial answer.

-

## 3 Answers

Here's one possibility switching to tikz-cd for the commutative diagram and using the tikzmark library to place some marks later used to draw the "rectangles" (notice, in particular, that the syntax for the diagram is the same):

\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz-cd}
\usetikzlibrary{tikzmark}

\begin{document}

\begin{tikzcd}[column sep=1cm,row sep=1cm]
0 \ar[r] & \tikzmark{startc}\Omega^0_X \ar[d] \ar[r] & \tikzmark{startb}\Omega_X^1 \ar[r] \ar[d] & \tikzmark{starta}\ldots \ar[r] & \Omega_X^n \ar[d] \ar[r] & 0 \\
\tikzmark{endc}0 \ar[r] & C^0(\Omega^0_X) \ar[d] \ar[r] & C^0(\Omega_X^1) \ar[r] \ar[d] & \ldots \ar[r] & C^0(\Omega_X^n) \ar[d] \ar[r] & 0 \\
\tikzmark{endb}0 \ar[r] & \tikzmark{enda}C^1(\Omega^0_X) \ar[d] \ar[r] & C^1(\Omega_X^1) \ar[r] \ar[d] & \ldots \ar[r] & C^1(\Omega_X^n) \ar[d] \ar[r] & 0 \\
&   \vdots                       & \vdots                        & \ldots        & \vdots                        & \\
\end{tikzcd}

\begin{tikzpicture}[remember picture,overlay]
\draw[rounded corners=20pt]
([xshift=-5pt,yshift=15pt]{pic cs:starta}) --
([xshift=50pt,yshift=15pt]pic cs:starta) --
([xshift=30pt,yshift=-15pt]pic cs:enda) --
([xshift=-30pt,yshift=-15pt]pic cs:enda) --
cycle
;
\draw[rounded corners=20pt]
([xshift=-10pt,yshift=15pt]{pic cs:startb}) --
([xshift=42pt,yshift=15pt]pic cs:startb) --
([xshift=0pt,yshift=-15pt]pic cs:endb) --
([xshift=-48pt,yshift=-15pt]pic cs:endb) --
cycle
;
\draw[rounded corners=20pt]
([xshift=-6pt,yshift=15pt]{pic cs:startc}) --
([xshift=42pt,yshift=15pt]pic cs:startc) --
([xshift=-6pt,yshift=-15pt]pic cs:endc) --
([xshift=-46pt,yshift=-15pt]pic cs:endc) --
cycle
;
\end{tikzpicture}

\end{document}


Adjust the values used for xshift and yshift according to your needs.

Another possibility with better shapes:

\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz-cd}
\usetikzlibrary{tikzmark}

\tikzset{
Enclose/.style={
draw,
opacity=0.2,
line width=#1,
line cap=round,
color=gray
}
}

\begin{document}

\begin{tikzpicture}[remember picture,overlay]
\draw[Enclose=30pt] ([xshift=10pt]pic cs:starta) -- ([xshift=15pt]pic cs:enda);
\draw[Enclose=30pt] ([xshift=5pt]pic cs:startb) -- ([xshift=-10pt]pic cs:endb);
\draw[Enclose=30pt] ([xshift=10pt]pic cs:startc) -- ([xshift=-10pt]pic cs:endc);
\end{tikzpicture}

\begin{tikzcd}[column sep=1cm,row sep=1cm]
0 \ar[r] & \tikzmark{startc}\Omega^0_X \ar[d] \ar[r] & \tikzmark{startb}\Omega_X^1 \ar[r] \ar[d] & \tikzmark{starta}\ldots \ar[r] & \Omega_X^n \ar[d] \ar[r] & 0 \\
\tikzmark{endc}0 \ar[r] & C^0(\Omega^0_X) \ar[d] \ar[r] & C^0(\Omega_X^1) \ar[r] \ar[d] & \ldots \ar[r] & C^0(\Omega_X^n) \ar[d] \ar[r] & 0 \\
\tikzmark{endb}0 \ar[r] & \tikzmark{enda}C^1(\Omega^0_X) \ar[d] \ar[r] & C^1(\Omega_X^1) \ar[r] \ar[d] & \ldots \ar[r] & C^1(\Omega_X^n) \ar[d] \ar[r] & 0 \\
&   \vdots                       & \vdots                        & \ldots        & \vdots                        & \\
\end{tikzcd}

\end{document}


The codes need three runs to stabilize.

-
That is perfect, thank you very much. Clearly I should be reading the tikz guide too! Thank you again! –  Joe Tait May 11 '14 at 14:43
From Gonzalo perfection would be a real nice ellipse not a fake ;-) –  Tarass May 11 '14 at 15:14
@Tarass I think the shapes are better now; I wasn't happy with the original ones. –  Gonzalo Medina May 11 '14 at 16:07
@JoeTait I added another option to my answer that might be of interest for you. –  Gonzalo Medina May 11 '14 at 16:08

Could this be what you want? a newcommand called circled is defined, taking one argument, via tikz, all you need to do is circled{object}.

Update: Use of tikzmark skill via tikz, based on OP's new explanations.

Code: updated

\documentclass[12pt]{article}
\usepackage[margin=1cm,paper size={20cm,15cm}]{geometry}
\usepackage{tabularx,array}
\usepackage{amsmath,tikz}
\usepackage[all]{xy}
\usetikzlibrary{calc,positioning}
\thispagestyle{empty}

\newcommand{\tikzmark}[1]{\tikz[overlay,remember picture] \node[outer sep=0pt, inner sep=0pt] (#1) {};
}

%\newcommand*\circled[1]{\tikz[baseline=(char.base)]{
%    \node[shape=circle,draw,minimum width=2cm,inner sep=2pt] (char) {$#1$};}}

\begin{document}
\begin{displaymath}
\xymatrix{
0 \ar[r] & \tikzmark{d}\Omega^0_X \ar[d] \ar[r] & \Omega_X^1 \ar[r] \ar[d] & \ldots \ar[r] &\tikzmark{b}{\Omega_X^n}  \ar[d] \ar[r] & 0 \\
\tikzmark{c}0 \ar[r] & C^0(\Omega^0_X) \ar[d] \ar[r] & C^0(\Omega_X^1) \ar[r] \ar[d] & {\ldots} \ar[r] & C^0(\Omega_X^n) \ar[d] \ar[r] & 0 \\
0 \ar[r] & C^1(\Omega^0_X)\ar[d] \ar[r] & {C^1(\Omega_X^1)} \ar[r] \ar[d] & \ldots \ar[r] & C^1(\Omega_X^n) \ar[d] \ar[r] & 0 \\
&   \tikzmark{a}{\vdots}                      & \vdots                        & \ldots        &   \vdots                        & \\
}
\end{displaymath}

\begin{tikzpicture}[overlay, remember picture]
\draw [rounded corners=10pt]($(a.south west)+(-0.5,-0.5)$) -- ($(a.south west)+(-0.5,0.6)$) -- ($(b.east)+(0.6,0.6)$)-- ($(b.east)+(0.6,-0.5)$)--cycle;
\draw [rounded corners=10pt]($(c.south west)+(-0.5,-0.5)$) -- ($(c.south west)+(-0.5,0.6)$) -- ($(d.east)+(0.6,0.6)$)-- ($(d.east)+(0.6,-0.5)$)--cycle;
\end{tikzpicture}
\end{document}


Code

\documentclass[12pt]{article}
\usepackage[margin=1cm,paper size={20cm,15cm}]{geometry}
\usepackage{tabularx,array}
\usepackage{amsmath,tikz}
\usepackage[all]{xy}
\thispagestyle{empty}
\newcommand*\circled[1]{\tikz[baseline=(char.base)]{
\node[shape=circle,draw,minimum width=2cm,inner sep=2pt] (char) {$#1$};}}

\begin{document}
\begin{displaymath}
\xymatrix{
0 \ar[r] & \Omega^0_X \ar[d] \ar[r] & \Omega_X^1 \ar[r] \ar[d] & \ldots \ar[r] & \circled{\Omega_X^n} \ar[d] \ar[r] & 0 \\
0 \ar[r] & C^0(\Omega^0_X) \ar[d] \ar[r] & C^0(\Omega_X^1) \ar[r] \ar[d] & \circled{\ldots} \ar[r] & C^0(\Omega_X^n) \ar[d] \ar[r] & 0 \\
0 \ar[r] & C^1(\Omega^0_X)\ar[d] \ar[r] & \circled{C^1(\Omega_X^1)} \ar[r] \ar[d] & \ldots \ar[r] & C^1(\Omega_X^n) \ar[d] \ar[r] & 0 \\
&   \circled{\vdots}                      & \vdots                        & \ldots        &   \vdots                        & \\
}
\end{displaymath}
\end{document}

-
Hi @jesse Thank you very much. That is close, but not quite - I would want all the objects you have circled to be in one circle (I guess it would be an ellipse), and then another circle containing the $C^0(\Omega_X^0)$ and $\Omega_X^1$, one just containing $\Omega_X^0$ and the second zero term on the left, etc. Apologies for the lack of clarity, I will edit the question. –  Joe Tait May 11 '14 at 13:46

With tikz only :

\documentclass[tikz,margin=2pt]{standalone}
\usepackage{}
\usetikzlibrary{calc,fit}

\begin{document}

\begin{tikzpicture}[x=2cm,y=-1.5cm,>=stealth]

\foreach \y [count=\Y from 0] in
{{0,\Omega^0_X,\Omega_X^1,\ldots,\Omega_X^n ,0},
{0,C^0(\Omega^0_X),C^0(\Omega_X^1),\ldots,C^0(\Omega_X^n),0},
{0,C^1(\Omega^0_X),C^1(\Omega_X^1),\ldots,C^1(\Omega_X^n),0},
{,\vdots,\vdots,\ldots,\vdots,}} {%
\foreach \x [count=\X from 0] in \y
{%
\node[inner sep=5pt] (\X\Y) at (\X,\Y) {$\x$} ;
}}

\foreach \y in {0,...,3}
\foreach \x [count=\i from 1] in {0,...,4} {%
\draw[->] (\x\y) -- (\i\y);
}

\foreach \x in {0,...,5}
\foreach \y [count=\i from 1] in {0,...,2} {%
\draw[->] (\x\y) -- (\x\i);
}

\node[draw=red, rounded corners=6pt, rotate fit=-50, inner sep =7pt, fit=(10) (01)] {};
\node[draw=red, rounded corners=6pt, rotate fit=-50, inner sep =1pt, fit=(20) (11) (02)] {};
\node[draw=red, rounded corners=6pt, rotate fit=-50, inner sep =1pt, fit=(12) (21) (30)] {};
\end{tikzpicture}

\end{document}

-
Hi @tarass As I commented on the above answer, this is not quite what I am looking for. I have added an extra picture to clarify. Sorry for the confusion and thank you for helping –  Joe Tait May 11 '14 at 14:22