# How to draw circles around multiple row cells and column cells

How to draw circles around multiple row cells and column cells as shown in attached figures.

I am using Professional lay out tables... i.e. Tables in tabular environment, Table below

I am also attaching my table of interest here where I want to highlight as shown in picture

\documentclass{article}
\usepackage{booktabs,multirow}

\begin{document}
\centering
\begin{tabular}{c c cc c } % centered columns (5 columns)
\toprule
&&\multicolumn{3}{c}{\textbf{J}}  \\
\cmidrule(l){2-5}
&&\multicolumn{2}{c}{\textbf{$M_J=1$}}& $\textbf{$M_J=2$}$  \\
\cmidrule(l){2-4}
&\textbf{I} & $\textbf{J=1}$ &$\textbf{J=2}$ & \\
\bottomrule
\multirow{2}{*}{\textbf{ $M_I=1$ } }&I=1 &      $n_{1111}$   &   $n_{1211}$  &  $n_{1+11}$\\
&I=2 &      $n_{2111}$   &   $n_{2211}$  &  $n_{2+11}$\\
\textbf{ $M_I=2$ } &  &       $n_{+121}$   &   $n_{+221}$  & $n_{++22}$\\
\bottomrule
\end{tabular}
\end{document}

• I made a MWE from your example (added packages you need and removed table-environment) – knut Oct 16 '13 at 19:21

How about using TikZ (in overlay mode)?

\documentclass{article}
\usepackage{tikz}

\begin{document}
\begin{table}
\begin{tabular}{|c|c|c|}
\hline
A&B&C\\
\hline
1&2&3\\
\hline
\end{tabular}

\begin{tikzpicture}[overlay]
\draw[red, line width=1.5pt] (1,0.3) ellipse (1cm and 0.2cm);
\draw[blue] (0.35,0.5) ellipse (0.2cm and 0.5cm);
\end{tikzpicture}
\end{table}
\end{document}

• This solution makes problems, if you move the content. The position must be adapted with each text modification inside the table. – knut Oct 16 '13 at 20:09

I have a solution with two new makros.

You can put content inside the \circled command and mark single cells.

To mark multiple cells you can use \markcells. The two obligatory parameters define x- and y-size. With the optional parameter you can define color and shift the result. This is not an optimal solution, it needs some manual adaptions until the positions are correct.

\documentclass{standalone}
\usepackage{booktabs,multirow}

\usepackage{tikz}
\usetikzlibrary{shapes}
\newcommand*{\circled}[2][red]{
\tikz[baseline=(char.base)]{
\node[shape=ellipse,inner sep=2pt,
draw=#1,
] (char) {#2};}
}
\newcommand{\markcells}[3][green]{
\tikz[baseline=(char.mid)]{\node[shape=ellipse,overlay,draw,#1]{\phantom{\rule{#2}{#3}}};}%
}
\begin{document}
\centering
\begin{tabular}{c c cc c } % centered columns (5 columns)
\toprule
&&\multicolumn{3}{c}{\textbf{J}}  \\
\cmidrule(l){2-5}
&&\multicolumn{2}{c}{\circled{\textbf{$M_J=1$}}}& $\textbf{$M_J=2$}$  \\
\cmidrule(l){2-4}
&\textbf{I} &
\markcells{20mm}{1em}
$\textbf{J=1}$ &$\textbf{J=2}$ & \\
\bottomrule
\multirow{2}{*}{\textbf{ $M_I=1$ } }&
\markcells[purple,shift={(1em,-1mm)}]{2em}{10mm}  I=1 &      $n_{1111}$   &   $n_{1211}$  &
\circled[blue]{$n_{1+11}$}\\
&I=2 &      $n_{2111}$   &   $n_{2211}$  &  $n_{2+11}$\\
\textbf{ $M_I=2$ } &  &
\circled{$n_{+121}$ }
&   $n_{+221}$  & $n_{++22}$\\
\bottomrule
\end{tabular}
\end{document}