3

In my article, I am trying to apply a color for a row in the table, when I am using \extracolsep\fill to fit the table to the text width, the rowcolor is splitted wherever the extra space added by a \extracolsep\fill. Is it possible to get the color shade without split by the automated way?

I am having lot of table in my article, I need to align the numbers by decimal, so I have added dcolumn.sty also. How can we get this color shaded without splitted by the automated way? Any trick is available?

Here is the MWE:

\documentclass{article}
\usepackage{dcolumn}
\usepackage[table,dvips]{xcolor}
\usepackage{showframe}
\newcolumntype{d}[1]{D{.}{.}{#1}}
\begin{document}

\rowcolors{2}{gray!35}{gray!70}
\begin{table}
\begin{tabular*}{\textwidth}{@{\extracolsep\fill}d{3,0}d{2,0}d{3,0}d{2,0}d{2,0}d{3,0}d{3,0}d{3,0}}
  \hline
  \rowcolor{blue!50}128&64&32&16&8&400&200&100\\
  \hline
  1   &0  &1   &1  &0  &1  &0  &1\\\hline
  1   &0  &100 &1  &0  &1  &0  &1\\\hline
  100 &0  &52  &1  &0  &1  &0  &1\\\hline
  1   &0  &1   &1  &0  &1  &0  &1\\\hline
\end{tabular*}
\end{table}
\end{document} 

I am getting this output:

Output

CarLaTeX
  • 62,716
RCV
  • 2,030
  • Could this help you? – CarLaTeX Feb 18 '17 at 02:39
  • @CarLaTeX I am using \rowcolors{2}{gray!35}{gray!70} from xcolor package to get the alternative color for a row, the above solution we need to go and give the command by the manual way in each and every row, and this solution is not working for a para align mode when the column is breaking a two or more line – RCV Feb 18 '17 at 02:54
  • @CarLaTeX we can get the the solution by using \tabcolsep, but we need to do more adjustment and more compilation to fix the table to the width, this will take so much time, i having more than 100 tables, it will be a tedious work. I am trying to get by the automated way!!! – RCV Feb 18 '17 at 02:58
  • @CarLaTeX Unfortunately the \rowcolor command seems to not care about the empty leading and ending spaces in the table, i.e. the @{}'s in the tabular 'preamble'. when I am using the @{} the color shade is going beyond the table width – RCV Feb 18 '17 at 03:02

1 Answers1

1

The siunitx package offers the possibility to choose the width of S columns. Here is a solution with this package – and colours to my taste ;o)

\documentclass{article}
\usepackage[table,dvipsnames, svgnames]{xcolor}
\usepackage{graphicx, siunitx}
\usepackage[showframe]{geometry}

\begin{document}

\begin{table}
  \setlength\extrarowheight{3pt}
  \sisetup{table-format=3.0, table-number-alignment=center, table-column-width=\dimexpr0.125\textwidth-2\tabcolsep}
  \rowcolors{2}{Gainsboro!80!Lavender}{Gainsboro!60!LightSteelBlue}
  \begin{tabular}{SS[table-format=2.0]SS[table-format=2.0]S[table-format=2.0]SSS}
    \hline
    \rowcolor{RoyalBlue!80} 128 & 64 & 32 & 16 & 8 & 400 & 200 & 100 \\
    \hline
    1 & 0 & 1 & 1 & 0 & 1 & 0 & 1 \\%\hline
    1 & 0 & 100 & 1 & 0 & 1 & 0 & 1 \\%\hline
    100 & 0 & 52 & 1 & 0 & 1 & 0 & 1 \\%\hline
    1 & 0 & 1 & 1 & 0 & 1 & 0 & 1 \\\hline
  \end{tabular}
\end{table}

\end{document} 

enter image description here

Bernard
  • 271,350