为 longtabus 着色(使用 rowcolors)

为 longtabus 着色(使用 rowcolors)

另一个绝望的 I-google-together-my-document 人在这里:在我的论文中,我想创建带有深灰色顶线的浅灰色表格,但遇到了 2 个问题:

如果我使用,\rowcolor[RGB]{240,240,240}我会得到结果,但我不明白在序言中定义颜色时我做错了什么。但这只是小问题。

最大的问题:我使用了一个longtabu环境,但无法\rowcolors使用它。

我希望它看起来像(有效):

\documentclass[11pt,a4paper, twoside]{scrbook}

\usepackage[english]{babel}
\usepackage{array}           
\usepackage{longtable, tabu}  
\usepackage[longtable,tabu]{xcolor}
\usepackage{colortbl} 
\definecolor{grey1}{rgb}{240,240,240}
\definecolor{grey2}{rgb}{250,250,250}

\begin{document}

\begin{longtabu}[H]{XXl}
\caption[Chemicals and Reagents] {\textbf{Chemicals and Reagents}} \vspace{2mm}\\
   \rowcolor[RGB]{240,240,240}
   \textbf{Product} & \textbf{Manufacturer} & \textbf{Reference}\\
   \rowcolor[RGB]{250,250,250}
   Whatever & from whomever & 123456789\\
   \rowcolor[RGB]{250,250,250}
   Whatever & from whomever & 123456789\\
   \rowcolor[RGB]{250,250,250}
   Whatever & from whomever & 123456789\\
\end{longtabu}

\end{document}

我期望更优雅的方式能够工作但却没有做到:

\documentclass[11pt,a4paper, twoside]{scrbook}

\usepackage[english]{babel}
\usepackage{array}           
\usepackage{longtable, tabu}  
\usepackage[longtable,tabu]{xcolor}
\usepackage{colortbl} 
\definecolor{grey1}{rgb}{240,240,240}
\definecolor{grey2}{rgb}{250,250,250}

\begin{document}

\rowcolors{1}{grey2}{grey2}
\begin{longtabu}[H]{XXl}
\caption[Chemicals and Reagents] {\textbf{Chemicals and Reagents}} \vspace{2mm}\\
   \rowcolor{grey1}
   \textbf{Product} & \textbf{Manufacturer} & \textbf{Reference}\\
   Whatever & from whomever & 123456789\\
   Whatever & from whomever & 123456789\\
   Whatever & from whomever & 123456789\\
\end{longtabu}

\end{document}

已经谢谢你了!

答案1

欢迎来到 TeX.SX!

tabu需要\taburowcolors命令,而不是\rowcolors

\documentclass[11pt,a4paper, twoside]{scrbook}

\usepackage{longtable,tabu}
\usepackage[table]{xcolor}
\definecolor{grey1}{gray}{0.6}
\definecolor{grey2}{gray}{0.9}

\begin{document}

\taburowcolors[2] 2 {grey2..grey2}
\begin{longtabu}[H]{XXl}
    \caption{Chemicals and Reagents}\\[2mm]
    \rowcolor{grey1}
    \textbf{Product} & \textbf{Manufacturer} & \textbf{Reference}\\
    Whatever & from whomever & 123456789\\
    Whatever & from whomever & 123456789\\
    Whatever & from whomever & 123456789\\
\end{longtabu}

\end{document}

结果:结果 2


弃用的答案,没有tabu

您的第二份文档的问题在于该\rowcolors命令需要table包的选项xcolor

\documentclass[11pt,a4paper, twoside]{scrbook}

\usepackage{longtable}  
\usepackage[table]{xcolor}
\definecolor{grey1}{gray}{0.6}
\definecolor{grey2}{gray}{0.9}

\begin{document}

\rowcolors{2}{grey2}{grey2}
\begin{longtable}{lll}
    \caption{Chemicals and Reagents}\\[2mm]
    \rowcolor{grey1}
    \textbf{Product} & \textbf{Manufacturer} & \textbf{Reference}\\
    Whatever & from whomever & 123456789\\
    Whatever & from whomever & 123456789\\
    Whatever & from whomever & 123456789\\
\end{longtable}

\end{document}

我已经改变了一些其他的事情,比如从 切换longtabu到。自从遇到以来,longtable我一直对tabu此主题不久前。不过,您的情况可能会有所不同,而且您的示例中的问题肯定不在这里。我只是想提一下。

grey1我还改变了我定义和颜色的方式grey2,只是为了向您展示这种可能性是存在的;如果您愿意,当然可以将其改回模型RGB(或更改灰色的色调)。

另外,您可以将其[2mm]作为可选参数传递给\\命令;无需在\vspace之前插入\\

结果:结果

答案2

使用 tabu 时,您应该使用 \taburowcolors 来交替颜色。如果您想要用值“240”等定义颜色,那么您必须使用 RGB 作为模型,而不是 rgb。

\documentclass[11pt,a4paper, twoside]{scrbook}

\usepackage[english]{babel}
\usepackage{array}
\usepackage[table]{xcolor}
\usepackage{longtable, tabu}


\definecolor{grey1}{RGB}{240,240,240}
\definecolor{grey2}{RGB}{250,250,250}

\begin{document}

\taburowcolors[1]{grey1..grey2}
\begin{longtabu}[H]{XXl}
\caption[Chemicals and Reagents] {\textbf{Chemicals and Reagents}} \vspace{2mm}\\
   \rowcolor{red}%to show it better
   \textbf{Product} & \textbf{Manufacturer} & \textbf{Reference}\\
   Whatever & from whomever & 123456789\\
   Whatever & from whomever & 123456789\\
   Whatever & from whomever & 123456789\\
\end{longtabu}

\end{document}

相关内容