6

我试图在我的文档中创建一个或多或少类似于下图中的表格的表格:

具有交替行着色的示例表

这张桌子应该水平拉伸到\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}

结果是:

带有表格的示例表*

好吧,备用行着色有效,但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}

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

带有 tabularx 的示例表

现在我已经没有想法了。有什么建议么?

4

1 回答 1

9

不是修复,而是破解,将 \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}
于 2011-04-12T00:19:07.810 回答