表格中的交替行颜色(*| x)?

Mar*_*zek 5 latex latex-environment

我正在尝试在我的文档中创建一个类似于下图中表格的表格:

具有备用行着色的示例表

该表应该水平拉伸到\textwidth.我的第一次尝试tabular*看起来像这样:

\documentclass{scrartcl}
\usepackage[table]{xcolor}
\definecolor{tableShade}{gray}{0.9}

\begin{document}
  \rowcolors{3}{tableShade}{white}  %% start alternating shades from 3rd row
  \noindent\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}lrrr}
    Something & foo & bar & baz \\
    Something & foo & bar & baz \\
    Something & foo & bar & baz \\
    Something & foo & bar & baz \\
    Something & foo & bar & baz \\
  \end{tabular*}
\end{document}
Run Code Online (Sandbox Code Playgroud)

结果是:

带表格*的示例表

好吧,备用行着色有效,但tabular*在列之间插入空格以将整个表拉伸到\textwidth.通过我的LaTeX伴侣浏览,我发现tabularx应该能够做我想要的.所以我将代码更改为:

\documentclass{scrartcl}
\usepackage[table]{xcolor}
\usepackage{tabularx}
\definecolor{tableShade}{gray}{0.9}

\begin{document}
  \rowcolors{3}{tableShade}{white}  %% start alternating shades from 3rd row
  \noindent\begin{tabularx}{\textwidth}{Xrrr}
    Something & foo & bar & baz \\
    Something & foo & bar & baz \\
    Something & foo & bar & baz \\
    Something & foo & bar & baz \\
    Something & foo & bar & baz \\
  \end{tabularx}
\end{document}
Run Code Online (Sandbox Code Playgroud)

现在,这看起来更像是它.但是tabularx忽略着色的起始行并从第一行开始.

使用tabularx的示例表

现在我的想法已经用完了.有什么建议?

coh*_*nsh 6

不是修复,而是黑客攻击,将\ hiderowcolors添加到第一行,然后使用\ showrowcolors重新打开颜色.看代码:

\rowcolors{3}{tableShade}{white}  %% start alternating shades from 3rd row
  \noindent\begin{tabularx}{\textwidth}{X X X X}%this can be {Xrrr} too
    \hiderowcolors 
     Something & foo & bar & baz \\
    \showrowcolors 
    Something & foo & bar & baz \\
    Something & foo & bar & baz \\
    Something & foo & bar & baz \\
    Something & foo & bar & baz \\
\end{tabularx}
Run Code Online (Sandbox Code Playgroud)


sam*_*ter 1

幸运的是,这样的事情不再是tabularray包的问题:

\documentclass{scrartcl}

\usepackage{xcolor}
\usepackage{tabularray}

\begin{document}

\noindent%
\begin{tblr}{
  colspec={XXXX},
  row{odd}={bg=lightgray},  
  row{1}={bg=black,fg=white},
}
  Something & foo & bar & baz \\
  Something & foo & bar & baz \\
  Something & foo & bar & baz \\
  Something & foo & bar & baz \\
  Something & foo & bar & baz \\
\end{tblr}  
  
\end{document}
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述