交替表格中的行颜色(*|x)?
我正在尝试在文档中创建一个或多或少类似于下图中的表格的表格:
该表格应该水平拉伸到 \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 会忽略着色的起始行并从第一行开始。
现在我已经没有想法了。有什么建议吗?
I’m trying to create a table in my document that resembles more or less the table in the picture below:
This table is supposed to be stretched horizontally to \textwidth
. My first attempt with tabular*
looked like this:
\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}
The result was:
Well, the alternate row coloring works but tabular*
inserts space between columns to stretch the whole table to \textwidth
. Browsing through my LaTeX companion I found that tabularx
should be able to do what I want. So I changed my code to look like that:
\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}
Now, this looks more like it. But tabularx
ignores the starting row for the coloring and starts with the first row.
Now I’ve run out of ideas. Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不是修复,而是一种破解,将 \hiderowcolors 添加到第一行,然后使用 \showrowcolors 重新打开颜色。参见代码:
Not a fix but a hack around, add \hiderowcolors to the first row, then turn colors back on with \showrowcolors. See code:
幸运的是,这些事情不再是
tabularray
包的问题:Luckily, such things are no longer a problem with the
tabularray
package: