0

I'm struggling with tables in latex. I would like to have the following "word" effect:

word style

but with the code:

\usepackage{booktabs}
\usepackage{colortbl}
\usepackage{xcolor}
\begin{center}
\begin{tabular}{c c c}
\textbf{INGESTION (Hz)} & \textbf{3 STREAMS} & \textbf{6 STREAMS}  \\ \toprule
\rowcolor{black!10}[0pt][0pt]50    & 1  & 1   \\
25    & 2  & 2 \\
\rowcolor{black!10}[0pt][0pt]15    & 3  & 3
\end{tabular}
\end{center}

I obtain this:

latex result

which is very ugly to me. Essentially I want to remove the space between the header and the first row, moreover I want remove the space between the cells of the rows (I used \arraystrech with terrible results). I'd like to add the extra header also.

Akinn
  • 135
  • Welcome to TeX.SE!. You can take a look at https://tex.stackexchange.com/questions/149841/booktab-color-rows-with-multicolumn and https://tex.stackexchange.com/questions/177202/booktabs-and-row-color?rq=1 – Cragfelt Nov 18 '17 at 00:20

3 Answers3

0

You could also use tabularx. To center the column type X you use column type Y defined in Centering in tabularx and X columns.

enter image description here

MWE:

\documentclass{article}
\usepackage{booktabs}
%\usepackage{colortbl}
\usepackage[table]{xcolor}

\usepackage{tabularx}
\newcolumntype{Y}{>{\centering\arraybackslash}X}
\begin{document}
  \rowcolors{3}{black!10}{white}  
  \begin{tabularx}{0.76\textwidth}{Ycc}
  \textbf{INGESTION (Hz)} & \textbf{3 STREAMS} & \textbf{6 STREAMS}  \\ \toprule
50    & 1  & 1   \\
25    & 2  & 2 \\
15    & 3  & 3
  \end{tabularx}
\end{document}
Bobyandbob
  • 4,899
0

The horizontal white strip is due to the padding added by the rules of booktabs. To remove it, you have to use \specialrule command, which gives you control on this padding for specific rules. The intercolumn white spaces are due to the optional [0pt]s in \rowcolor. Just suppress them. However a better solution, for alternating row colors is to use the \rowcolors command defined by xcolor with [table] option. Tthis option loads colortbl, so you don't have to do it.

Here's the result: \documentclass{article} \usepackage[utf8]{inputenc} \usepackage{booktabs} \usepackage[table, svgnames]{xcolor}

\begin{document}

\begin{center}
  \rowcolors{3}{Gainsboro}{white}
  \begin{tabular}{c c c}
    \multicolumn{3}{c}{\textbf{AVERAGE DATA LOSS (\%)}}\\
    \addlinespace
    \textbf{INGESTION (Hz)} & \textbf{3 STREAMS} & \textbf{6 STREAMS} \\
    \specialrule{\heavyrulewidth}{\aboverulesep}{0pt}
    50 & 1 & 1 \\
    25 & 2 & 2 \\
    15 & 3 & 3 \
  \end{tabular}
\end{center}

\end{document} 

enter image description here

Bernard
  • 271,350
0

You can use a customized command to color the rows

\documentclass[a4paper,10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{colortbl}
\usepackage{amsmath}
\usepackage{xcolor}
\usepackage{booktabs}

\newcommand{\ra}[1]{\renewcommand{\arraystretch}{#1}}
\colorlet{tablerowcolor}{black!10} % Table row separator colour = 10% gray
\newcommand{\rowcol}{\rowcolor{tablerowcolor}} %

\begin{document}

\begin{table}[!htpb]
\centering
\begin{tabular}{ccc}\toprule
\textbf{INGESTION(Hz)} & \textbf{3 STREAMS}& \textbf{6 STREAMS} \\ \toprule
\rowcol         50      & 1                     & 1             \\
                25      & 2                     & 2             \\
\rowcol         15      & 3                     & 3             \\ \bottomrule
\end{tabular}
\end{table}

\end{document}

enter image description here

Cragfelt
  • 4,005