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.

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

  • I find this the simple way. do you have any suggestions to add an extra header like the "word" style? – Akinn Nov 18 '17 at 1:11
  • @AndreaGiordano: Do you mean something like ‘Average Data Loss’ in your post? – Bernard Nov 18 '17 at 10:24
  • yes, I would like to add it – Akinn Nov 19 '17 at 19:07
  • @AndreaGiordano: The code has been updated, mylord! – Bernard Nov 19 '17 at 19:20
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}
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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