1

How can I use \multicolumn together with overlays?

\multicolumn fails if there is an overlay before it or if \multicolumn is used inside an overlay.

I actually want to do the last. \only<2>{\multicolumn{2}{c}{three}\\}

MWE:

\documentclass{beamer}

\usepackage{siunitx}

\begin{document}

\begin{frame}
\begin{tabular}{*{4}{|>{$}{c}<{$}}|}
\hline
a & b & c & d\\
\hline
1 & 2 & 3 & 4\\
\hline
%TODO following works
\multicolumn{2}{c}{one}\\
\only<2>{one\\}
%TODO following doesn't work
%\only<2>{two\\}
%\multicolumn{2}{c}{two}\\
%TODO following doesn't work
%\only<2>{\multicolumn{2}{c}{three}\\}
\end{tabular}
\end{frame}

\end{document}
user1
  • 2,196

2 Answers2

2

As far as I can tell, you want something like

\documentclass{beamer}

\usepackage{siunitx}


\begin{document}

\begin{frame}
\begin{tabular}{*{4}{|>{$}{c}<{$}}|}
\hline
aaa & b & c & d\\
\hline
1 & 2 & 3 & 4\\
\hline
\multicolumn{1}{l}{th}
\only<1>{\\\multicolumn{2}{l}{}}
\only<2>{\\\multicolumn{2}{l}{th}}
\end{tabular}
\end{frame}

\end{document}

Or the following, which makes the same output in this case.

\documentclass{beamer}

\usepackage{siunitx}



\begin{document}

\begin{frame}
\begin{tabular}{*{4}{|>{$}{c}<{$}}|}
\hline
aaa & b & c & d\\
\hline
1 & 2 & 3 & 4\\
\hline
\multicolumn{1}{l}{th}\\
\multicolumn{2}{l}{\only<2>{th}}
\end{tabular}
\end{frame}

\end{document}
David Carlisle
  • 757,742
  • Your second solution doesn't work nice, if you change it to something like \multicolumn{2}{l}{\only<2>{th2}}\\ \multicolumn{3}{l}{\only<3>{th3}} by this there if an empty line (or one have to get the first parameter get calculated basing on \onlys) – user1 Nov 11 '17 at 20:56
  • Your first solution is fine. Thanks. To achieve, what I actually want, just delete \\ \hline \multicolumn{1}{l}{th} and add \hline before the two \multicolumns like \\\hline\multicolumn – user1 Nov 11 '17 at 20:58
1

Right now I got:

\documentclass{beamer}

\usepackage{siunitx}

\newlength{\widthoffirstcolumn}
\settowidth{\widthoffirstcolumn}{%
\begin{tabular}{>{$}{c}<{$}}% %here are not | on purpose (still not the exact indent)
aaa\\
1
\end{tabular}%
}

\begin{document}

\begin{frame}
\begin{tabular}{*{4}{|>{$}{c}<{$}}|}
\hline
aaa & b & c & d\\
\hline
1 & 2 & 3 & 4\\
\hline
\multicolumn{1}{l}{th}\\ %only for testing the indent of next row
\multicolumn{1}{c}{}\only<2>{&\multicolumn{2}{l}{\hspace{-\widthoffirstcolumn}th}\\}
\end{tabular}
\end{frame}

\end{document}

The \multicolumn{1}{c}{} is for not getting vertical lines

The \hspace{-\widthoffirstcolumn} goes back the to start of the row


I'm not sure if this is a nice solution, but it works... (the rowstart isn't calculated exactly)

user1
  • 2,196