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.

A three line table is used for my report. I want to fill lightgray background color to the whole table, but there is white space between rows, how to eliminate this issue?

  1. Without \addlinespace: there is still white space around rules enter image description here

  2. With \addlinespace: this is ideal spacing between rows, but how to fill colour as well for these white spaces? enter image description here


  \usepackage{colortbl}
  \definecolor{Lightgray}{RGB}{235,235,235}

Code:

  \begin{table} [htpb]
  \centering
  \begin{minipage}[b]{0.9 \textwidth}
  \centering
  \begin{threeparttable}[b]

  \caption{Size and shape distribution for a sampled rock riprap} 
  \label{tab:size_shape}
  \begin{tabular} { p{0.15 \textwidth}  p{0.10 \textwidth} p{0.10 \textwidth} p{0.10 \textwidth} p{0.15 \textwidth}  } 
  \toprule
  \rowcolor{Lightgray}& Small    &  Medium &  Large & Shape fraction \\        \cmidrule{1-5}  \addlinespace
  \rowcolor{Lightgray}Compact    & 10\% &  44\% & 7\% & 61\% \\ \addlinespace
  \rowcolor{Lightgray}Flat       & 4\%  &  10\% & 4\% & 18\% \\ \addlinespace       
  \rowcolor{Lightgray}Elongated  & 5\%  &  12\% & 4\% & 21\% \\ \addlinespace
  \midrule
  \rowcolor{Lightgray}Size fraction  & 19\% & 66\% & 15\% & 100\% \\
  \bottomrule
  \end{tabular}
  \end{threeparttable}
  \end{minipage}
  \end{table} `

Edit 1: Using \renewcommand{\arraystretch}{1.3} gets proper spacing between rows without \addlinespace. The remaining issue is: how to get ride of the whihte space for rules?

Edit 2: The solution of Professional-looking tables with alternating row colors still could not eliminate white space after midline or cmidrule. Hence white colour is used for the row after midline to hide the white space. If wrong please correct me.

See the table created by the new commands of that solution: enter image description here

   \begin{table} [htpb]
   \centering
   \begin{minipage}[b]{0.9 \textwidth}
   \centering
   \begin{threeparttable}[b]

   \caption{Size and shape distribution for a sampled rock riprap} 
   \label{tab:size_shape}
   \begin{tabular} { p{0.15 \textwidth}  p{0.10 \textwidth} p{0.10 \textwidth} p{0.10 \textwidth} p{0.15 \textwidth}  } 
   \topline
   \headcol & Small  &  Medium &  Large & Shape fraction \\% \cmidrule{1-5}  
   \midline
   \rowcol Compact    & 10\% &  44\% & 7\% & 61\% \\ 
   \rowcol Flat       & 4\%  &  10\% & 4\% & 18\% \\ % \cellcolor{lightgray}  
   \rowcol Elongated  & 5\%  &  12\% & 4\% & 21\% \\ 
   \midline
   \rowcol Size fraction  & 19\% & 66\% & 15\% & 100\% \\
   \bottomlinec  %\bottomrule
   \end{tabular}
   \end{threeparttable}
   \end{minipage}
   \end{table}

Besides, if you enlarge the table and look carefully, you will see few thin white lines in the heading row! Is that normal?

See below: lines

share|improve this question
    
See Werner's answer to tex.stackexchange.com/q/33758. –  Gonzalo Medina Jan 12 '13 at 19:28
    
The answer codes of tex.stackexchange.com/q/33758 seems not working. –  KOF Jan 12 '13 at 19:34
    
Can you please add to your question a complete document with the code you used to produce the image? (I mean the one containing the commands from the answer I linked to in my previous comment). –  Gonzalo Medina Jan 12 '13 at 20:15
    
Please look to the final commands to produce the table below. –  KOF Jan 12 '13 at 21:02
add comment

1 Answer 1

up vote 9 down vote accepted

After looking into the new commands provided by Werner, it seems that the mideline is redefined by 3 rules with top colour, middle colour and bottom colour.

So two new commands were added to make a perfect colour filled table:

  1. Middle line connecting heading row and the second row

    \colorlet{blcolor}{gray!80}
    
    \newcommand{\rowmidlineHR}{\arrayrulecolor{tableheadcolor}
      \specialrule{\aboverulesep}{0pt}{0pt}%
      \arrayrulecolor{black}\specialrule{\lightrulewidth}{0pt}{0pt}%
      \arrayrulecolor{tablerowcolor}\specialrule{\belowrulesep}{0pt}{0pt}%
      \arrayrulecolor{black}}
      % Command \rowmidlinewc consists of 3 rules
      % (top colour tableheadcolor, middle colour black, bottom colour tablerowcolor)
    
  2. Secondary gray middle line

    \newcommand{\rowmidlineG}{\arrayrulecolor{tablerowcolor}%
      \specialrule{\aboverulesep}{0pt}{0pt}%
      \arrayrulecolor{blcolor}\specialrule{\lightrulewidth}{0pt}{0pt}%
      \arrayrulecolor{tablerowcolor}\specialrule{\belowrulesep}{0pt}{0pt}%
      \arrayrulecolor{black}}
    % Command \rowmidlineG consists of 3 rules
    % (top colour tablerowcolor, middle colour black, bottom colour tablerowcolor)
    

Final table: perfect table

and the codes:

\renewcommand{\arraystretch}{1.3}

\begin{table} [htpb]
\centering
\begin{minipage}[b]{0.9 \textwidth}
\centering
\begin{threeparttable}[b]

\caption{Size and shape distribution for a sampled rock riprap} 
\label{tab:size_shape}
\begin{tabular} { p{0.15 \textwidth}  p{0.10 \textwidth} p{0.10 \textwidth} p{0.10 \textwidth} p{0.15 \textwidth}  } 
\topline
\headcol & Small  &  Medium &  Large & Shape fraction \\
\rowmidlineHR  % Head Rule
\rowcol Compact    & 10\% &  44\% & 7\% & 61\% \\ 
\rowcol Flat       & 4\%  &  10\% & 4\% & 18\% \\ 
\rowcol Elongated  & 5\%  &  12\% & 4\% & 21\% \\ 
\rowmidlineG % Gray midline
\rowcol Size fraction  & 19\% & 66\% & 15\% & 100\% \\
\bottomlinec
\end{tabular}
\end{threeparttable}
\end{minipage}
\end{table}
share|improve this answer
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.