2

I am trying to use the only<1>, only<2>, etc... feature of beamer for a frame. However, when add it to the program, it is not compiling. I would appreciate any help.

Also, how can the titles, "prediction outcomes" and "actual outcomes" be centered rather than left-aligned?

Where is there a list of beamer color options (instead of blue as is in the code)?

How can I make an arrow to point to the cell?

This is continued from: Making a table as a box in beamer in whch 2 cells are highlighted

\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}

I tried putting the only around the begin{tikzpicture} and end{tikzpicture}.

3
  • 1
    There are many questions in here, can you please make it more to the point? Also there are no \only commands right now. When does it not work? Also there is no arrow now. Can you make it a complete code compatible with the question?
    – percusse
    Jul 26, 2012 at 13:20
  • Colour processing in beamer and tikz comes from the xcolor package. That can be loaded with vast lists of named colours. See the xcolor documentation for details. If you put \PassOptionsToPackage{svgnames}{xcolor} at the very start of the document to load the svgnames, for example. Jul 26, 2012 at 13:36
  • Where is the list?
    – J G
    Jul 26, 2012 at 16:42

1 Answer 1

5

(I'm answering the \only part as I judge that the main question here.)

It doesn't look like it on the surface, but this is the same underlying problem as your original question: when using a matrix in a tikzpicture, the ampersand must not be seen too early. With the \begin{frame} ... \end{frame} construction of the original question then the whole frame is read in before it is processed, and this means that the ampersand is read too early. The fragile option is a work-a-round for this. However, the fragile option only works for the \begin{frame} ... \end{frame} construction. When you enclose the tikzpicture in an \only then once again the whole picture is read in (as it is the argument to the \only command) before it is processed so the ampersand is read too early. There are ways around this, for example using \onslide<1> before the tikzpicture, but these might not interact well with more complicated overlay specifications.

There is an alternative way to get round this ampersand issue and this is what I recommend in this case. That is to use the key ampersand replacement in the argument to the matrix path construction. The most common use is: \matrix[..., ampersand replacement=\&,...] { ... \& ... \\ }; but any command can be used. This command is used to replace the ampersand in the matrix construction. Thus:

\documentclass[professionalfont, fleqn]{beamer}
%\url{http://tex.stackexchange.com/q/64774/86}
\usepackage{tikz}
\usetikzlibrary{arrows,shapes,positioning,fit,shapes.misc}

\begin{document}

 \begin{frame}

 \centering
\only<1>{%
 \begin{tikzpicture}[
  box/.style = {draw,rectangle,minimum size=1.0cm,text
width=1cm,align=center}
 ]
 \matrix (conmat) [row sep=0cm,column sep=0cm,ampersand
replacement=\&] {
 \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}%
}

\pause
Second frame

\end{frame}
\end{document}

This will be the most robust solution for you, I think.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .