Is it possible to make a box around two nodes in a tikzpicture? Specifically, I am making a 2 by 2 box, and I have some labels outside of the box. For example, I have a + and a 0 in the same row and underneath and box. Could I make some sort of circle (oval) around them? Similarly, for the 0 and the - on the right side of the box, outside of it? Can these circles both extend to include that plus sign on the bottom right outside the box?
For an approximate graphic of what the code produces, see: making a box in beamer -- adding labels diagonally
Thank you very much for your help!
\documentclass[professionalfont, fleqn]{beamer}
\usepackage{tikz}
\usetikzlibrary{arrows,shapes,positioning,fit,shapes.misc,matrix}
% commands for the cell colors
\def\coloroneone#1{\def\Coloroneone{#1}}
\def\coloronetwo#1{\def\Coloronetwo{#1}}
\def\colortwoone#1{\def\Colortwoone{#1}}
\def\colortwotwo#1{\def\Colortwotwo{#1}}
\begin{document}
\begin{frame}
% initial colors
\coloroneone{blue!60}
\coloronetwo{white}
\colortwoone{blue!60}
\colortwotwo{white}
\only<1-4>{%
\centering
\begin{tikzpicture}
% definitions of colors for the four initial slides
\only<2>{% colors for second slide
\coloroneone{white}
\coloronetwo{blue!60}
\colortwoone{white}
\colortwotwo{blue!60}}
\only<3>{% colors for third slide
\coloroneone{red!30}
\coloronetwo{red!30}
\colortwoone{white}
\colortwotwo{white}}
\only<4>{% colors for fourth slide
\coloroneone{white}
\colortwoone{red!30}
\colortwotwo{red!30}}
% the matrix
\matrix
[
matrix of nodes,
ampersand
replacement=\&,
nodes={draw,rectangle,minimum size=1.0cm,text width=2cm,text depth=1cm,text height=.8cm,align=center,inner sep=0pt},
row sep=0cm,
column sep=0cm
] (mat)
{
|[fill=\Coloroneone]|
\&
|[fill=\Coloronetwo]| Smaller \\
|[fill=\Colortwoone]| Smaller
\&
|[fill=\Colortwotwo]| \\
};
% the labels
\node[left=.5cm of mat,text width=1.5cm,align=center] {\textbf{actual \\ value}};
\node[above=.5cm of mat] {\textbf{prediction}};
\node[anchor=south] at (mat-1-1.north) {$\mathbf{p}$};
\node[anchor=south] (n) at (mat-1-2.north) {$\mathbf{n}$};
\node[anchor=east] at (mat-1-1.west) {$\mathbf{p'}$};
\node[anchor=east] (np) at (mat-2-1.west) {$\mathbf{n'}$};
\only<1-4>{\node[anchor=north] at (mat-2-1.south) [below = 2pt+7pt]{$\textbf{{+}}$};}
\only<2-4>{\node[anchor=north] at (mat-2-2.south) [below = 2pt+7pt]{$\textbf{{0}}$};}
\only<3-4>{\node[anchor=west] at (mat-1-2.east) [right = 2pt+10pt]{$\textbf{{0}}$};}
\only<4-4>{\node[anchor=west] at (mat-2-2.east) [right = 2pt+10pt]{$\textbf{{--}}$};}
\only<1-4>\node[anchor=north] at ([yshift=-8.75mm, xshift=-2mm]np.south){\textbf{A}};
\only<3-4>\node[anchor=west] at ([xshift=8mm]n.east) {\textbf{D}};
\only<4-4>\node[font=\color{red}, anchor=north] at ([yshift=-9.5mm, xshift=51mm]np.south){\textbf{+}};
\end{tikzpicture}
}
\only<5>{Some text}
\end{frame}
\end{document}
