1

In a table, I have rows represented as gray and white colors using \rowcolors{3}{}{gray!20}. Here, I want to split columns using white color line instead of black. The way I created column lines using | but I cannot define its color.

Example is take from Table with multiple columns, with small changes I made.

\usepackage{booktabs} \usepackage[table]{xcolor}

\begin{document} \begin{table}[htp]
    \centering
    \rowcolors{3}{gray!20}{}
    \begin{tabular}{
      l|
      *{3}{S[table-format=1.4]}|
      *{3}{S[table-format=1.4]}
      S[table-format=5]
      }
      \toprule
      \multicolumn{1}{c}{Data Set}       &
      \multicolumn{3}{c}{Balanced Error} &
      \multicolumn{3}{c}{Area Under Curve}                                                         \\
      \cmidrule(lr){2-4} \cmidrule(lr){5-7}
                                         & {Train} & {Valid} & {Test} & {Train} & {Valid} & {Test} \\
      \midrule
      arcene                             & 0.5000  & 0.4886  & 0.5006 & 0.5000  & 0.5114  & 0.4994 \\
      gisette                            & 0.5000  & 0.4886  & 0.5006 & 0.5000  & 0.5114  & 0.4994 \\
      dexter                             & 0.5000  & 0.4886  & 0.5006 & 0.5000  & 0.5114  & 0.4994 \\
      madelon                            & 0.5000  & 0.4886  & 0.5006 & 0.5000  & 0.5114  & 0.4994 \\
      \bottomrule
    \end{tabular} \end{table} \end{document} ```

output:

enter image description here

Instead the the drawning column line (|) black, can it be white, example output would be:

enter image description here

2 Answers 2

2

It is possible to use !{\color{white}\vrule} as provided by the colortbl package (which is loaded by \usepackage[table]{xcolor}):

\documentclass{article}
\usepackage{booktabs} 
\usepackage[table]{xcolor}
\usepackage{siunitx}

\begin{document}
\begin{table}[htp]
    \centering
    \rowcolors{3}{gray!20}{}
    \begin{tabular}{
      l!{\color{white}\vrule}
      *{3}{S[table-format=1.4]}!{\color{white}\vrule}
      *{3}{S[table-format=1.4]}
      S[table-format=5]
      }
      \toprule
      \multicolumn{1}{c}{Data Set}       &
      \multicolumn{3}{c}{Balanced Error} &
      \multicolumn{3}{c}{Area Under Curve}                                                         \\
      \cmidrule(lr){2-4} \cmidrule(lr){5-7}
                                         & {Train} & {Valid} & {Test} & {Train} & {Valid} & {Test} \\
      \midrule
      arcene                             & 0.5000  & 0.4886  & 0.5006 & 0.5000  & 0.5114  & 0.4994 \\
      gisette                            & 0.5000  & 0.4886  & 0.5006 & 0.5000  & 0.5114  & 0.4994 \\
      dexter                             & 0.5000  & 0.4886  & 0.5006 & 0.5000  & 0.5114  & 0.4994 \\
      madelon                            & 0.5000  & 0.4886  & 0.5006 & 0.5000  & 0.5114  & 0.4994 \\
      \bottomrule
    \end{tabular}
\end{table}
\end{document}

enter image description here

2
  • is it possible to shift the rule in x-axis? For example if Balanced Error is long string like Balanced Error Balanced Error and when I try to draw ruler in between Train in Valid columns, it does not show up in the middle
    – alper
    Sep 29, 2022 at 9:43
  • 1
    Please note that \color{white}\vrule is not provided by colortbl, this is possible using array and color (both of which are loaded by colortbl).
    – Skillmon
    Sep 29, 2022 at 12:43
1

It is fairly easy to achieve with tabularray

enter image description here

\documentclass{article}
\usepackage{xcolor}
\usepackage{tabularray}
\UseTblrLibrary{siunitx,booktabs}
 
\begin{document}
\centering
\begin{tblr}{
    colspec = {
      l
      *{3}{S[table-format=1.4]}
      *{3}{S[table-format=1.4]}
    },
    row{odd} = {bg=gray!10},
    row{1} = {bg=white},
    hline{2} = {2-4}{leftpos=-1,rightpos=-1,endpos,\cmidrulewidth},
    hline{2} = {5-7}{leftpos=-1,rightpos=-1,endpos,\cmidrulewidth},
    vline{2,5} = {3-Z}{fg=white,1.2pt},
  }
  \toprule
  Data Set
  & \SetCell[c=3]{c} {{{Balanced Error}}} &&
  & \SetCell[c=3]{c} {{{Area Under Curve}}} && \\
  & {{{Train}}} & {{{Valid}}} & {{{Test}}} & {{{Train}}} & {{{Valid}}} & {{{Test}}} \\
  \midrule
  arcene   & 0.5000  & 0.4886  & 0.5006 & 0.5000  & 0.5114  & 0.4994 \\
  gisette  & 0.5000  & 0.4886  & 0.5006 & 0.5000  & 0.5114  & 0.4994 \\
  dexter   & 0.5000  & 0.4886  & 0.5006 & 0.5000  & 0.5114  & 0.4994 \\
  madelon  & 0.5000  & 0.4886  & 0.5006 & 0.5000  & 0.5114  & 0.4994 \\
  \bottomrule
\end{tblr}
\end{document}

You must log in to answer this question.

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