wd=<dimen>
not only sets the width of the beamercolorbox
to <dimen>
, it sets the \hsize
to <dimen>
. So you're centering a box in a line which has the same width as the box, resulting in nothing.
So to force centering, use some \hfill
s:
\documentclass{beamer}
\setbeamercolor{bgcolor}{fg=black,bg=blue}
\begin{document}
\begin{frame}
\hfill
\begin{beamercolorbox}[rounded=true, center, shadow=true,wd=6cm]{bgcolor}
Some text goes here...
\end{beamercolorbox}
\hfill\hfill
\end{frame}
\end{document}
I'm not sure why you need two at the end—it seems like one at the front and back would do the centering. But instead you just get a box flush right. So an extra one does the trick.
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}
Best Answer
Instead of manually fiddling around with the boxes and their parameter, I would simply let beamer do the work for you and use blocks.
Additional advantage:
block
s know all the nice beamer features, such as overlays etc.If the predefined types of blocks (block, example, alert, theorem, proof ...) are not enough, you could add new ones. Either cheating by adding new theorems or you could define new ones:
Off-topic and just my personal opinion: I would not mix boxes of different style (e.g. with and without shadow, rounded corner vs. rectangular ones) in the same presentation.