Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'd like to draw a partial horizontal line just below of 'first second third' row, but \cline doesn't work. Any suggestion?

\documentclass[table]{beamer}
\usepackage[T1]{fontenc}
\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]{.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}
share|improve this question
1  
Welcome to TeX.SE. The \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 use rowcolor and a \cline to separate rows? Seems like only one should be necessary to do the job. –  Peter Grill Jan 1 '12 at 2:26
    
@Herbert Thanks for removing the {beamer} tag -- I hadn't been sure if beamer was relevant to this question. –  lockstep Jan 2 '12 at 10:18
add comment

2 Answers 2

up vote 8 down vote accepted

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.

  1. 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:

    enter image description here

  2. 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}

    enter image description here

  3. 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}
share|improve this answer
add comment

that is only a problem with the pdf viewer. Here is your example without any change:

enter image description here

Increasing or decreasing the zoom gives a "hidden" line. You must controll the behaviour with your viewer in the full-screen mode. And if the line is present can also be tested with a printed output which should show all lines.

share|improve this answer
1  
I tried with Acrobat 10.1 on Mac and it does not display the horizontal line, but surprisingly Mac Preview does show it!! However, Section 10 of the colortbl documentation seems to indicate that a feature of \cline is that "they are covered up by any colour pannels in the following row". –  Peter Grill Jan 1 '12 at 17:37
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.