3

I'd like to uncover a table row-by-row in a NiceTabular environment (provided by the nicematrix package). My table has alternating row colors, and I'd like overlay to cover/uncover the row color and its content at the same time. I'd also like to stick to the nicematrix package instead of using the conventional tabular/array environments.

I tried several ways that work in tabular and similar environments, but not in NiceTabular. These include:

MWE

\documentclass{beamer}
\usepackage{nicematrix,booktabs}

\begin{document} \begin{frame} \centering \begin{NiceTabular}{m{.4\textwidth}m{.4\textwidth}} \CodeBefore \rowcolor{gray!50}{1} % heading \rowcolors{2}{gray!25}{} % body \Body \toprule \onslide<2->{Head 1 & Head 2} \ \midrule Row 1 Col 1 & Row 1 Col 2 \pause\ Row 2 Col 1 & Row 2 Col 2 Row 2 Col 2 Row 2 Col 2 Row 2 Col 2 \ \bottomrule \end{NiceTabular}

Overlay in conventional \texttt{tabular} for comparison: \begin{tabular}{m{.4\textwidth}m{.4\textwidth}} \toprule \onslide<2->{Head 1 & Head 2} \ \midrule Row 1 Col 1 & Row 1 Col 2 \pause\ Row 2 Col 1 & Row 2 Col 2 Row 2 Col 2 Row 2 Col 2 Row 2 Col 2 \ \bottomrule \end{tabular} \end{frame} \end{document}

Herr K.
  • 17,946
  • 4
  • 61
  • 118
  • Your MWE is not very clear (at least for me): there is two cells with the content Row 1 Col 1. Is it by design? – F. Pantigny Nov 12 '21 at 15:50
  • @F.Pantigny: Sorry they are just typos from copy-pasting. I'll fix that. BTW, thank you for the excellent package! – Herr K. Nov 12 '21 at 15:53

2 Answers2

3

Here is what I would do.

\documentclass{beamer}
\usepackage{nicematrix,booktabs}

\begin{document} \begin{frame}[t] \centering \begin{NiceTabular}{m{.4\textwidth}m{.4\textwidth}} \CodeBefore \rowcolor{gray!50}{1} \rowcolors{2}{gray!25}{} \Body \toprule Head 1 & Head 2 \ \midrule \only<2-> { Row 1 Col 1 & text text text text text text text text text text } \only<3-> { \ Row 2 Col 1 & text text text text text } \only<4-> { \ Row 3 Col 1 & text text text text text text text text text } \only<5-> { \ Row 4 Col 1 & text text \ \bottomrule } \end{NiceTabular} \end{frame} \end{document}

As usual with nicematrix, you need several compilations.


If you accept to write in white the text that must be hidden, you have also the following solution (with a centered vertical position of the tabular).

\documentclass{beamer}
\usepackage{nicematrix,booktabs}

\begin{document} \begin{frame} \centering \color{white} \begin{NiceTabular}{m{.4\textwidth}m{.4\textwidth}}[rules/color=black] \CodeBefore \rowcolor{gray!50}{1} \Body \toprule \RowStyle[color=black]{} Head 1 & Head 2 \ \midrule \only<2->{\RowStyle[color=black,rowcolor=gray!25]{}} Row 1 Col 1 & text text text text text text text text text text \ \only<3->{\RowStyle[color=black]{}} Row 2 Col 1 & text text text text text \ \only<4->{\RowStyle[color=black,rowcolor=gray!25]{}} Row 3 Col 1 & text text text text text text text text text \ \only<5->{\RowStyle[color=black]{}} Row 4 Col 1 & text text \ \bottomrule \end{NiceTabular} \end{frame} \end{document}

F. Pantigny
  • 40,250
  • Thanks. This is almost what I want. It'd be nice if the table does not need to be top-aligned. Is it possible for nicematrix environments to process TikZ styling options such as visible on? – Herr K. Nov 12 '21 at 18:18
  • Is there a reason why you nest the \only's? They seem to work also when issued separately on each row (before the \\). – Herr K. Nov 12 '21 at 18:20
  • @HerrK. You are right: there is no point nesting the \only. I have changed my answer. – F. Pantigny Nov 12 '21 at 19:07
  • 1
    @HerrK. At this time, I don't see any way to have visible on working for rows in nicematrix. I will investigate. – F. Pantigny Nov 12 '21 at 19:22
  • Thank you very much. I'll go with your second solution. – Herr K. Nov 13 '21 at 01:22
2

It seems to be possible if you use \onslide inside of each cell. This might be a lot of code depending on the complexity of your table, though.

I tried the following:

\documentclass{beamer}
\usepackage{nicematrix,booktabs}

\begin{document}

\begin{frame} \centering \begin{NiceTabular}{m{.4\textwidth}m{.4\textwidth}} \CodeBefore \rowcolor{gray!50}{1} % heading \onslide<3->{\rowcolors{2}{gray!25}{}} % body \Body \toprule Head 1 & Head 2 \ \midrule \onslide<2->{Row 1 Col 1} & \onslide<2->{Row 1 Col 2} \ \onslide<3->{Row 2 Col 1} & \onslide<3->{Row 2 Col 2} \ \bottomrule \end{NiceTabular} \end{frame}

\end{document}

... and got the following output:

enter image description here