19

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

2 Answers 2

10

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

1
  • Can this also be set globally instead of for each tabular?
    – rugk
    Aug 29, 2020 at 11:55
1

With {NiceTabular} of nicematrix, you have directly and easily the expected output.

\documentclass[9pt]{extbook}
\usepackage{xcolor}

\usepackage{nicematrix}

\usepackage{booktabs}


\begin{document}

\renewcommand{\arraystretch}{1.3}

\begin{NiceTabular}{@{}*{6}{>$c<$}@{}}
\CodeBefore 
    \rowcolor{gray!25}{1} 
    \rowcolors{3}{gray!10}{}
\Body
\toprule 
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]\\ 
\midrule
x_0&{y_0}&&&& \\
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]}&& \\
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]} \\
\vdots &\vdots &\vdots &\vdots &\vdots &\vdots  \\
\bottomrule
\end{NiceTabular}

\end{document}

You need several compilations (because nicematrix uses PGF/Tikz nodes under the hood).

Ouput of the above code

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .