[Tex/LaTex] Booktabs and row color

booktabs

As you may know, there is a problem of white space when you try to color rows with book tabs. I found the above solution.

However, when you use @{} in \begin{tabular}{@{}*{6}{>$c<$}@{}}
(in order to suppress the space in the edges) some color remains
on the left and right, and I do not know how to put it off.

Thanks

\documentclass[9pt]{extbook}
\usepackage[french]{keystroke}
\usepackage[utf8]{inputenc}
\usepackage{amsmath,amsfonts,amssymb,amsthm}
\usepackage[table]{xcolor}

\usepackage{array,multicol}

\usepackage[T1]{fontenc}
\usepackage{lmodern} 
\usepackage[francais]{babel}

\usepackage{booktabs}



\colorlet{tableheadcolor}{gray!25} % Table header colour = 25% gray
\newcommand{\headcol}{\rowcolor{tableheadcolor}} %he
\colorlet{tablerowcolor}{gray!10} % Table row separator colour = 10% gray
\newcommand{\rowcol}{\rowcolor{tablerowcolor}} %
    % Command \topline consists of a (slightly modified) \toprule followed by a \heavyrule rule of colour tableheadcolor (hence, 2 separate rules)
\newcommand{\topline}{\arrayrulecolor{black}\specialrule{0.1em}{\abovetopsep}{0.5pt}%
            \arrayrulecolor{tableheadcolor}\specialrule{\belowrulesep}{0pt}{-3pt}%
            \arrayrulecolor{black}
            }
    % Command \midline consists of 3 rules (top colour tableheadcolor, middle colour black, bottom colour white)
\newcommand{\midline}{\arrayrulecolor{tableheadcolor}\specialrule{\aboverulesep}{-1pt}{0pt}%
            \arrayrulecolor{black}\specialrule{\lightrulewidth}{0pt}{0pt}%
            \arrayrulecolor{white}\specialrule{\belowrulesep}{0pt}{-3pt}%
            \arrayrulecolor{black}
            }
    % Command \rowmidlinecw consists of 3 rules (top colour tablerowcolor, middle colour black, bottom colour white)
\newcommand{\rowmidlinecw}{\arrayrulecolor{tablerowcolor}\specialrule{\aboverulesep}{0pt}{0pt}%
            \arrayrulecolor{black}\specialrule{\lightrulewidth}{0pt}{0pt}%
            \arrayrulecolor{white}\specialrule{\belowrulesep}{0pt}{0pt}%
         \arrayrulecolor{black}}
    % Command \rowmidlinewc consists of 3 rules (top colour white, middle colour black, bottom colour tablerowcolor)
\newcommand{\rowmidlinewc}{\arrayrulecolor{white}\specialrule{\aboverulesep}{0pt}{0pt}%
            \arrayrulecolor{black}\specialrule{\lightrulewidth}{0pt}{0pt}%
            \arrayrulecolor{tablerowcolor}\specialrule{\belowrulesep}{0pt}{0pt}%
            \arrayrulecolor{black}}
    % Command \rowmidlinew consists of 1 white rule
\newcommand{\rowmidlinew}{\arrayrulecolor{white}\specialrule{\aboverulesep}{0pt}{0pt}%
            \arrayrulecolor{black}}
    % Command \rowmidlinec consists of 1 tablerowcolor rule
\newcommand{\rowmidlinec}{\arrayrulecolor{tablerowcolor}\specialrule{\aboverulesep}{0pt}{0pt}%
            \arrayrulecolor{black}}
    % Command \bottomline consists of 2 rules (top colour
\newcommand{\bottomline}{\arrayrulecolor{white}\specialrule{\aboverulesep}{0pt}{-2pt}%
            \arrayrulecolor{black}\specialrule{\heavyrulewidth}{0pt}{\belowbottomsep}}%
\newcommand{\bottomlinec}{\arrayrulecolor{tablerowcolor}\specialrule{\aboverulesep}{0pt}{0pt}%
            \arrayrulecolor{black}\specialrule{\heavyrulewidth}{0pt}{\belowbottomsep}}%

\begin{document}

\renewcommand{\arraystretch}{1.3}

\begin{tabular}{@{}*{6}{>$c<$}@{}} 
\topline \headcol
x_i&y_i&\Delta[x_{i-1},x_i]&\Delta[x_{i-2},x_{i-1},x_i]&\Delta[x_{i-3},x_{i-2},x_{i-1},x_i]&\Delta[x_{i-4},x_{i-3},x_{i-2},x_{i-1},x_i]\\ \midline
x_0&{y_0}&&&& \\
\rowcol x_1&y_1&{\Delta[x_0,x_1]}&&& \\
x_2&y_2&\Delta[x_1,x_2]&{\Delta[x_0,x_1,x_2]}&& \\
\rowcol x_3&y_3&\Delta[x_2,x_3]&\Delta[x_1,x_2,x_3]&{\Delta[x_0,x_1,x_2,x_3]}& \\
x_4&y_4&\Delta[x_3,x_4]&\Delta[x_2,x_3,x_4]&\Delta[x_1,x_2,x_3,x_4]&{\Delta[x_0,x_1,x_2,x_3,x_4]} \\
\rowcol \vdots &\vdots &\vdots &\vdots &\vdots &\vdots  \\
\bottomline
\end{tabular}
\vspace{1cm}

\begin{tabular}{*{6}{>$c<$}} 
\topline \headcol
x_i&y_i&\Delta[x_{i-1},x_i]&\Delta[x_{i-2},x_{i-1},x_i]&\Delta[x_{i-3},x_{i-2},x_{i-1},x_i]&\Delta[x_{i-4},x_{i-3},x_{i-2},x_{i-1},x_i]\\ \midline
x_0&{y_0}&&&& \\
\rowcol x_1&y_1&{\Delta[x_0,x_1]}&&& \\
x_2&y_2&\Delta[x_1,x_2]&{\Delta[x_0,x_1,x_2]}&& \\
\rowcol x_3&y_3&\Delta[x_2,x_3]&\Delta[x_1,x_2,x_3]&{\Delta[x_0,x_1,x_2,x_3]}& \\
x_4&y_4&\Delta[x_3,x_4]&\Delta[x_2,x_3,x_4]&\Delta[x_1,x_2,x_3,x_4]&{\Delta[x_0,x_1,x_2,x_3,x_4]} \\
\rowcol \vdots &\vdots &\vdots &\vdots &\vdots &\vdots  \\
\bottomline
\end{tabular}
\end{document}

enter image description here

Best Answer

You can use some \kerning like

\begin{tabular}{>{\kern-\tabcolsep}*{6}{>$c<$}<{\kern-\tabcolsep}}

Code:

\documentclass[9pt]{extbook}
\usepackage[french]{keystroke}
\usepackage[utf8]{inputenc}
\usepackage{amsmath,amsfonts,amssymb,amsthm}
\usepackage[table]{xcolor}

\usepackage{array,multicol}

\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[francais]{babel}

\usepackage{booktabs}



\colorlet{tableheadcolor}{gray!25} % Table header colour = 25% gray
\newcommand{\headcol}{\rowcolor{tableheadcolor}} %he
\colorlet{tablerowcolor}{gray!10} % Table row separator colour = 10% gray
\newcommand{\rowcol}{\rowcolor{tablerowcolor}} %
    % Command \topline consists of a (slightly modified) \toprule followed by a \heavyrule rule of colour tableheadcolor (hence, 2 separate rules)
\newcommand{\topline}{\arrayrulecolor{black}\specialrule{0.1em}{\abovetopsep}{0.5pt}%
            \arrayrulecolor{tableheadcolor}\specialrule{\belowrulesep}{0pt}{-3pt}%
            \arrayrulecolor{black}
            }
    % Command \midline consists of 3 rules (top colour tableheadcolor, middle colour black, bottom colour white)
\newcommand{\midline}{\arrayrulecolor{tableheadcolor}\specialrule{\aboverulesep}{-1pt}{0pt}%
            \arrayrulecolor{black}\specialrule{\lightrulewidth}{0pt}{0pt}%
            \arrayrulecolor{white}\specialrule{\belowrulesep}{0pt}{-3pt}%
            \arrayrulecolor{black}
            }
    % Command \rowmidlinecw consists of 3 rules (top colour tablerowcolor, middle colour black, bottom colour white)
\newcommand{\rowmidlinecw}{\arrayrulecolor{tablerowcolor}\specialrule{\aboverulesep}{0pt}{0pt}%
            \arrayrulecolor{black}\specialrule{\lightrulewidth}{0pt}{0pt}%
            \arrayrulecolor{white}\specialrule{\belowrulesep}{0pt}{0pt}%
         \arrayrulecolor{black}}
    % Command \rowmidlinewc consists of 3 rules (top colour white, middle colour black, bottom colour tablerowcolor)
\newcommand{\rowmidlinewc}{\arrayrulecolor{white}\specialrule{\aboverulesep}{0pt}{0pt}%
            \arrayrulecolor{black}\specialrule{\lightrulewidth}{0pt}{0pt}%
            \arrayrulecolor{tablerowcolor}\specialrule{\belowrulesep}{0pt}{0pt}%
            \arrayrulecolor{black}}
    % Command \rowmidlinew consists of 1 white rule
\newcommand{\rowmidlinew}{\arrayrulecolor{white}\specialrule{\aboverulesep}{0pt}{0pt}%
            \arrayrulecolor{black}}
    % Command \rowmidlinec consists of 1 tablerowcolor rule
\newcommand{\rowmidlinec}{\arrayrulecolor{tablerowcolor}\specialrule{\aboverulesep}{0pt}{0pt}%
            \arrayrulecolor{black}}
    % Command \bottomline consists of 2 rules (top colour
\newcommand{\bottomline}{\arrayrulecolor{white}\specialrule{\aboverulesep}{0pt}{-2pt}%
            \arrayrulecolor{black}\specialrule{\heavyrulewidth}{0pt}{\belowbottomsep}}%
\newcommand{\bottomlinec}{\arrayrulecolor{tablerowcolor}\specialrule{\aboverulesep}{0pt}{0pt}%
            \arrayrulecolor{black}\specialrule{\heavyrulewidth}{0pt}{\belowbottomsep}}%

\begin{document}

\renewcommand{\arraystretch}{1.3}

\begin{tabular}{>{\kern-\tabcolsep}*{6}{>$c<$}<{\kern-\tabcolsep}}
\topline \headcol
x_i&y_i&\Delta[x_{i-1},x_i]&\Delta[x_{i-2},x_{i-1},x_i]&\Delta[x_{i-3},x_{i-2},x_{i-1},x_i]&\Delta[x_{i-4},x_{i-3},x_{i-2},x_{i-1},x_i]\\ \midline
x_0&{y_0}&&&& \\
\rowcol x_1&y_1&{\Delta[x_0,x_1]}&&& \\
x_2&y_2&\Delta[x_1,x_2]&{\Delta[x_0,x_1,x_2]}&& \\
\rowcol x_3&y_3&\Delta[x_2,x_3]&\Delta[x_1,x_2,x_3]&{\Delta[x_0,x_1,x_2,x_3]}& \\
x_4&y_4&\Delta[x_3,x_4]&\Delta[x_2,x_3,x_4]&\Delta[x_1,x_2,x_3,x_4]&{\Delta[x_0,x_1,x_2,x_3,x_4]} \\
\rowcol \vdots &\vdots &\vdots &\vdots &\vdots &\vdots  \\
\bottomline
\end{tabular}
\vspace{1cm}

\begin{tabular}{>{\kern-\tabcolsep}*{6}{>$c<$}<{\kern-\tabcolsep}}
\topline \headcol
x_i&y_i&\Delta[x_{i-1},x_i]&\Delta[x_{i-2},x_{i-1},x_i]&\Delta[x_{i-3},x_{i-2},x_{i-1},x_i]&\Delta[x_{i-4},x_{i-3},x_{i-2},x_{i-1},x_i]\\ \midline
x_0&{y_0}&&&& \\
\rowcol x_1&y_1&{\Delta[x_0,x_1]}&&& \\
x_2&y_2&\Delta[x_1,x_2]&{\Delta[x_0,x_1,x_2]}&& \\
\rowcol x_3&y_3&\Delta[x_2,x_3]&\Delta[x_1,x_2,x_3]&{\Delta[x_0,x_1,x_2,x_3]}& \\
x_4&y_4&\Delta[x_3,x_4]&\Delta[x_2,x_3,x_4]&\Delta[x_1,x_2,x_3,x_4]&{\Delta[x_0,x_1,x_2,x_3,x_4]} \\
\rowcol \vdots &\vdots &\vdots &\vdots &\vdots &\vdots  \\
\bottomline
\end{tabular}
\end{document}

enter image description here

Related Question