Use the fragile
option for the frame:
\documentclass[professionalfont, fleqn]{beamer}
\usepackage{tikz}
\usetikzlibrary{arrows,shapes,positioning,fit,shapes.misc}
\begin{document}
\begin{frame}[fragile]
\centering
\begin{tikzpicture}[
box/.style = {draw,rectangle,minimum size=1.0cm,text width=1cm,align=center}
]
\matrix (conmat) [row sep=0cm,column sep=0cm] {
\node (tpos) [box,label=left:\( \mathbf{p'} \),label=above:\( \mathbf{p} \),] {};
& \node (fneg) [box,label=above:\textbf{n},] {$\checkmark$}; \\
\node (fpos) [box,label=left:\( \mathbf{n'} \),] {$\checkmark$};
& \node (tneg) [box] {$\checkmark$}; \\
};
\node [left=.05cm of conmat,text width=1.5cm,align=center] {\textbf{actual \\ value}};
\node [above=.05cm of conmat] {\textbf{prediction outcome}};
\end{tikzpicture}
\end{frame}
\end{document}
To control the positioning, you can use some standard commands such as \centering
, \vfill
, \vspace
or \hspace
.
An example showing two alternatives to fill columns or rows; the first one using an argumant for the box
style (each \node can then be filled with an independent color) and the second one using column <number>/.style
, and/or row <number>/.style
to apply the color to a whole column or row:
\documentclass[professionalfont, fleqn]{beamer}
\usepackage{tikz}
\usetikzlibrary{arrows,shapes,positioning,fit,shapes.misc}
\begin{document}
\begin{frame}[fragile]
\vspace*{-1cm}\hspace*{2cm}
\begin{tikzpicture}[
box/.style = {draw,rectangle,minimum size=1.0cm,text width=1cm,align=center,fill=#1}
]
\matrix (conmat) [row sep=0cm,column sep=0cm] {
\node (tpos) [box=white,label=left:\( \mathbf{p'} \),label=above:\( \mathbf{p} \),] {};
& \node (fneg) [box=blue!40,label=above:\textbf{n},] {$\checkmark$}; \\
\node (fpos) [box=white,label=left:\( \mathbf{n'} \),] {$\checkmark$};
& \node (tneg) [box=blue!40] {$\checkmark$}; \\
};
\node [left=.05cm of conmat,text width=1.5cm,align=center] {\textbf{actual \\ value}};
\node [above=.05cm of conmat] {\textbf{prediction outcome}};
\end{tikzpicture}
\begin{tikzpicture}[column 1/.style={every node/.style={fill=red!30}},
box/.style = {draw,rectangle,minimum size=1.0cm,text width=1cm,align=center}
]
\matrix (conmat) [row sep=0cm,column sep=0cm] {
\node (tpos) [box,label=left:\( \mathbf{p'} \),label=above:\( \mathbf{p} \),] {};
& \node (fneg) [box,label=above:\textbf{n},] {$\checkmark$}; \\
\node (fpos) [box,label=left:\( \mathbf{n'} \),] {$\checkmark$};
& \node (tneg) [box] {$\checkmark$}; \\
};
\node [left=.05cm of conmat,text width=1.5cm,align=center] {\textbf{actual \\ value}};
\node [above=.05cm of conmat] {\textbf{prediction outcome}};
\end{tikzpicture}
\begin{tikzpicture}[row 2/.style={every node/.style={fill=olive!30}},
box/.style = {draw,rectangle,minimum size=1.0cm,text width=1cm,align=center}
]
\matrix (conmat) [row sep=0cm,column sep=0cm] {
\node (tpos) [box,label=left:\( \mathbf{p'} \),label=above:\( \mathbf{p} \),] {};
& \node (fneg) [box,label=above:\textbf{n},] {$\checkmark$}; \\
\node (fpos) [box,label=left:\( \mathbf{n'} \),] {$\checkmark$};
& \node (tneg) [box] {$\checkmark$}; \\
};
\node [left=.05cm of conmat,text width=1.5cm,align=center] {\textbf{actual \\ value}};
\node [above=.05cm of conmat] {\textbf{prediction outcome}};
\end{tikzpicture}
\end{frame}
\end{document}
I am definitely unfamiliar with both beamer
and tikz
(do not quite get what the \only
are supposed to do) but perhaps this could go in the direction you want:
\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{chains}
\newcounter{count}
% helper macro:
\long\def\GobToSemiColon #1;{}
\newcommand\myPicture{
\begin{tikzpicture}
\begin{scope}[start chain = going below]
\ifnum\value{count}<1 \expandafter\GobToSemiColon\fi
\ifnum\value{count}>3 \expandafter\GobToSemiColon\fi
\node[draw, rectangle, on chain] {display only when counter is between
1 and 3};
\ifnum\value{count}>-1 \expandafter\GobToSemiColon\fi
\node[draw, rectangle, on chain] {display only when counter is
negative};
\ifnum\value{count}<100 \expandafter\GobToSemiColon\fi
\ifnum\value{count}>200 \expandafter\GobToSemiColon\fi
\node[draw, rectangle, on chain] {display only if counter is between
100 and 200};
\ifnum\value{count}<3 \expandafter\GobToSemiColon\fi
\ifnum\value{count}>20 \expandafter\GobToSemiColon\fi
\node[draw, circle, on chain] {only when counter is in the range 3 to 20};
\end{scope}
\end{tikzpicture}
}
\begin{document}
\begin{frame}
\only{\setcounter{count}{-3}\myPicture}
\only{\setcounter{count}{105}\myPicture}
\only{\setcounter{count}{39}\myPicture}
\only{\setcounter{count}{2}\myPicture}
\only{\setcounter{count}{5}\myPicture}
\end{frame}
\end{document}
Best Answer
I made three changes:
&&
with&
(I don't understand of purpose of double ampersands, you only cross limit of normal matrix size -- 10 columns)