As I mentioned in the comments, the \cline
is working but is hidden due to the coloring of the rows, and it seems to me to be a bit of an overkill to use both a horizontal rule along with coloring to separate a row.
My suggestion would be to remove the row color in the second row, and use \cellcolor
to ensure that the \multirow
text is properly colored:
Another option is to use \cmidrule
from the booktabs
package (see Known Issues below).
This package highly recommends that you not use vertical lines in tables, but have left them in as that was in the original MWE. Note that this also requires setting
\setlength{\aboverulesep}{0pt}
and
\setlength{\belowrulesep}{0pt}
Use the \hhline
package which provides a command similar to \hline
which takes a parameter similar to a tabular
specification, so that vertical lines can be properly handled. The output of this is similar to that produced in #2 above. (see Known Issues below)
Known Issues
- Both the
booktabs
and hhline
solutions have an issue in that there is a white line in the \multirow
text which I do not know how to fix.
Code: Remove row color from second row:
\documentclass[table]{beamer}
\usepackage{xcolor,multirow}
\begin{document}
%%%
\begin{frame}
\frametitle{table example}
\begin{table}[h]
\centering
\rowcolors[]{2}{blue!20}{blue!10}
\begin{tabular}{|c|cccccc|} \hline
\rowcolor[gray]{.9}
&
\multicolumn{2}{>{\columncolor[gray]{.9}}c}{first} &
\multicolumn{2}{>{\columncolor[gray]{.9}}c}{second} &
\multicolumn{2}{>{\columncolor[gray]{.9}}c|}{third} \\
\cline{2-7}
\rowcolor[gray]{1}
\multirow{-2}{*}{left\cellcolor[gray]{.9}}
& $x_1$ & $x_2$ & $x_3$ & $x_4$ & $x_5$ & $x_6$ \\ \hline
A & a1 & a2 & a3 & a4 & a5 & a6 \\
B & b1 & b2 & \multicolumn{2}{>{\columncolor{blue!20}}c}{b34} & b5 & b6 \\
C & c1 & c2 & c3 & c4 & c5 & c6 \\
D & d1 & d2 & d3 & d4 & d5 & d6 \\ \hline
\end{tabular}
\end{table}
\end{frame}
\end{document}
Code: Use booktabs
package:
\documentclass[table]{beamer}
\usepackage{xcolor,multirow}
\usepackage{booktabs}
\setlength{\aboverulesep}{0pt}
\setlength{\belowrulesep}{0pt}
\begin{document}
%%%
\begin{frame}
\frametitle{table example}
\begin{table}[h]
\centering
\rowcolors[]{2}{blue!20}{blue!10}
\begin{tabular}{|c|cccccc|} \hline
\rowcolor[gray]{.9}
&
\multicolumn{2}{>{\columncolor[gray]{.9}}c}{first} &
\multicolumn{2}{>{\columncolor[gray]{.9}}c}{second} &
\multicolumn{2}{>{\columncolor[gray]{.9}}c|}{third} \\
\cmidrule{2-7}
\rowcolor[gray]{.9}
\multirow{-2}{*}{left}
& $x_1$ & $x_2$ & $x_3$ & $x_4$ & $x_5$ & $x_6$ \\ \hline
A & a1 & a2 & a3 & a4 & a5 & a6 \\
B & b1 & b2 & \multicolumn{2}{>{\columncolor{blue!20}}c}{b34} & b5 & b6 \\
C & c1 & c2 & c3 & c4 & c5 & c6 \\
D & d1 & d2 & d3 & d4 & d5 & d6 \\ \hline
\end{tabular}
\end{table}
\end{frame}
\end{document}
Code: hhline
package:
\documentclass[table]{beamer}
\usepackage{xcolor,multirow}
\usepackage{hhline}
\begin{document}
%%%
\begin{frame}
\frametitle{table example}
\begin{table}[h]
\centering
\rowcolors[]{2}{blue!20}{blue!10}
\begin{tabular}{|c|cccccc|} \hline
\rowcolor[gray]{.9}
&
\multicolumn{2}{>{\columncolor[gray]{.9}}c}{first} &
\multicolumn{2}{>{\columncolor[gray]{.9}}c}{second} &
\multicolumn{2}{>{\columncolor[gray]{.9}}c|}{third} \\
%\cline{2-7}
\hhline{~|------}
\rowcolor[gray]{.9}
\multirow{-2}{*}{left}
& $x_1$ & $x_2$ & $x_3$ & $x_4$ & $x_5$ & $x_6$ \\ \hline
A & a1 & a2 & a3 & a4 & a5 & a6 \\
B & b1 & b2 & \multicolumn{2}{>{\columncolor{blue!20}}c}{b34} & b5 & b6 \\
C & c1 & c2 & c3 & c4 & c5 & c6 \\
D & d1 & d2 & d3 & d4 & d5 & d6 \\ \hline
\end{tabular}
\end{table}
\end{frame}
\end{document}
\cline
is working fine. However you are also coloring the rows and hence it does not show up. If you comment out the\rowcolor
commands you'll see that it is working. Are you sure you want to userowcolor
and a\cline
to separate rows? Seems like only one should be necessary to do the job.beamer
was relevant to this question.