# circle items in an array

So I would like to circle two of the elements in my array at the same time. Even though they are in different rows and or columns. Here is what I have so far.

\documentclass{article}

\begin{document}

$\begin{array}{cccc} x_{1}&x_{2}&x_{3}&x_{4}\\ y_{1}&y_{2}&y_{3}&y_{4} \end{array}$

\end{document}


I want to put a big circle around x_{1} and y_{1} as well as a circle around x_{3} and x_{4}. Any ideas how to do this?

A simple solution, if you are not bound to use circles:

\documentclass{article}

\newcommand\mul[1]{\multicolumn{1}{c}{#1}}

\begin{document}

$\begin{array}{|c|c|cc|} \cline{1-1}\cline{3-4} x_{1} & \multicolumn{1}{c|}{x_{2}} & x_{3} & x_{4} \\ \cline{3-4} y_{1} & \mul{y_{2}} & \mul{y_{3}} & \mul{y_{4}} \\ \cline{1-1} \end{array}$

\end{document}


One option using TikZ (I used a rectangle with rounded corners; a circle woul be too big in my opinion):

\documentclass{article}
\usepackage{tikz}

\newcommand\Circle[1]{%
\tikz[baseline=(char.base)]\node[circle,draw,inner sep=2pt] (char) {#1};}

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

\begin{document}

$\begin{array}{cccc} \Circle{x_{1}} & x_{2} & \Circle{x_{3}} & \Circle{x_{4}} \\ \Circle{y_{1}} & y_{2} & y_{3} & y_{4} \end{array}$

$\begin{array}{cccc} \tikzmark{starta}{x_{1}} & x_{2} & \tikzmark{startb}{x_{3}} & \tikzmark{endb}{x_{4}} \\ \tikzmark{enda}{y_{1}} & y_{2} & y_{3} & y_{4} \end{array}$

\begin{tikzpicture}[remember picture,overlay]
\draw[cyan,rounded corners]
([xshift=-5pt,yshift=5pt]starta.north west)
rectangle
([xshift=8pt,yshift=-5pt]enda);
\draw[cyan,rounded corners]
([xshift=-5pt,yshift=5pt]startb.north west)
rectangle
([xshift=8pt,yshift=-6pt]endb);
\end{tikzpicture}

\end{document}


And using hf-tikz:

\documentclass{article}
\usepackage[markings]{hf-tikz}

\begin{document}

$\begin{array}{cccc} \tikzmarkin[mark at=0.93]{col 1}(0.5,0.35)(-0.2,-0.7) x_{1} & x_{2} & \tikzmarkin[mark at=0.93]{col 1}(1.2,0.35)(-0.2,-0.15)x_{3} & x_{4} \\ y_{1} & y_{2} & y_{3} & y_{4} \end{array}$

\end{document}


• I want to make one big circle that contains $x_{1}$ and $y_{1}$. The same for $x_{3}$ and $x_{4}$. Maybe an array isn't the best thing to do here. – user90401 Sep 18 '13 at 2:13
• @user90401 Then you might want to take a look at this answer: tex.stackexchange.com/a/83331/6870 – Philipp Sep 18 '13 at 2:15