Background: I encounter some unexpected situations while overlaying a tikz matrix
in Beamer. The latex code is given at the end (note: you can also read and copy it at ShareLatex:TikzMatrixOverlay). There are two tikz matrices and the first one without overlay is for comparison. The second matrix with overlay is not satisfying in the following ways:
- The
|[red]|
instruction for the (2,1) cell (second row, first column) does not work; notice that the|[red]|
instruction for the (3,2) cell does work.- I cannot replace the
\only<4>{4444 & 4444 & 4444} \\
by\only<4>{4444 & 4444 & 4444 \\}
. Otherwise, I will get theMissing \endgroup inserted
error.- If I use
\only<4>{4444 & 4444 & 4444} \\
(as the source code indicated), an extra empty cell (in the fourth row) is shown during the overlay.
Notice that you can also see the comments in source code and the image below for the three problems.
Problem: Therefore, my problem is how to fix these three problems. Specifically,
- To enable the
|[red]|
instruction for the (2,1) cell;- To eliminate the extra empty cell (in the fourth row) during the overlay;
- To overlay the tikz matrix row by row.
\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}
\begin{frame}[fragile]{TikzMatrixOverlay}
\begin{tikzpicture}
% matrix without overlay for comparison
\matrix [align = center, matrix of nodes, nodes = {text width = 16mm, draw}]
{
1 & 1 & 1 \\
|[red]| 22 & 22 & 22 \\
333 & |[red]| 333 & 333 \\
4444 & 4444 & 4444 \\
};
% matrix with overlay
\matrix [align = center, xshift = 6.0cm, matrix of nodes, nodes = {text width = 16mm, draw}]
{
1 & 1 & 1 \\
\only<2->{|[red]| 22 & 22 & 22 \\} % Problem 1: the |[red]| instruction does not work.
\only<3->{333 & |[red]| 333 & 333 \\} % this |[red]| instruction does work.
\only<4>{4444 & 4444 & 4444} \\ % Problem 2: it cannot be: \only<4>{4444 & 4444 & 4444 \\}
};
\end{tikzpicture}
\end{frame}
\end{document}
visible on<>
style to always draw all elements, but hide those that should not yet be visible.|
character as the first token in a cell and only interprets|[red||
as a style in that case. So in the second matrix, it sees the\only
and so figures that there aren't any style options. Try putting the style option before the\only
. I think I would also confine\only
to a cell-by-cell basis on that last row.\only
(i.e.,|[red]| \only<2->{22 & 22 & 22 \\}
) works for the (2,1) cell. However, what is the meaning of confining\only
to a cell-by-cell basis? Do you mean\only<4>{4444} & \only<4>{4444} & \only<4>{4444} \\
? This does not help. And how about the '\\ '?There is still an extra empty cell during the overlay (and it is red on the second slide). You can check the SharedLatex code here.