我正在使用 longtable 绘制一个跨几页的表格。我还添加了代码来交替显示表格中的行颜色。
- 有没有办法用不同的颜色来给第一行着色?
- 如何确保标题字符串没有被彩色化?
我的 MWE 如下
\PassOptionsToPackage{table}{xcolor}
\documentclass{book}
\usepackage{fontspec}
\usepackage{longtable}
\renewcommand{\baselinestretch}{1.5}
\usepackage{titlesec}
\newcounter{magicrownumbers}
\newcommand\rownumber{\stepcounter{magicrownumbers}\arabic{magicrownumbers}}
\usepackage[dvipsnames]{xcolor}
\definecolor{light-gray}{HTML}{E5E4E2}
\definecolor{light-cyan}{HTML}{E0FFFF}
\begin{document}
\def\arraystretch{1}
\begin{center}
\rowcolors{1}{light-cyan}{light-gray}
\begin{longtable}{|p{.10\textwidth}| p{.98\textwidth}| p{.10\textwidth}|}
\hline
serial num. & sutra & sutra number \\
\hline
\rownumber & foo &1-1-56 \\
\hline
\rownumber & bar & 1-1-57 \\
\hline
\caption{caption for this table}
\end{longtable}
\end{center}
\end{document}
答案1
您可以使用 更改\rowcolor{}
标题行的行颜色,并使用\hiderowcolors
和\showrowcolors
避免给标题着色。
例如:
\documentclass{article}
\usepackage{longtable}
\usepackage[dvipsnames,table]{xcolor}
\definecolor{light-gray}{HTML}{E5E4E2}
\definecolor{light-cyan}{HTML}{E0FFFF}
\begin{document}
\rowcolors{1}{light-cyan}{light-gray}
\begin{longtable}{|*{3}{p{.3\textwidth}|}}
\hiderowcolors
\caption{Fine caption}\\
\showrowcolors
\hline
\rowcolor{magenta}Head 1 & Head 2 & Head 3\\\hline\endfirsthead
\hline
\rowcolor{yellow}Head 1 & Head 2 & Head 3\\\hline\endhead
\hline\endfoot
Content 1 & Content 2 & Content 3\\
Content 1 & Content 2 & Content 3\\
Content 1 & Content 2 & Content 3\\
Content 1 & Content 2 & Content 3\\
Content 1 & Content 2 & Content 3\\
Content 1 & Content 2 & Content 3\\
Content 1 & Content 2 & Content 3\\
Content 1 & Content 2 & Content 3\\
Content 1 & Content 2 & Content 3\\
Content 1 & Content 2 & Content 3\\
Content 1 & Content 2 & Content 3\\
Content 1 & Content 2 & Content 3\\
Content 1 & Content 2 & Content 3\\
Content 1 & Content 2 & Content 3\\
Content 1 & Content 2 & Content 3\\
Content 1 & Content 2 & Content 3\\
Content 1 & Content 2 & Content 3\\
Content 1 & Content 2 & Content 3\\
Content 1 & Content 2 & Content 3\\
Content 1 & Content 2 & Content 3\\
Content 1 & Content 2 & Content 3\\
Content 1 & Content 2 & Content 3\\
Content 1 & Content 2 & Content 3\\
Content 1 & Content 2 & Content 3\\
Content 1 & Content 2 & Content 3\\
Content 1 & Content 2 & Content 3\\
Content 1 & Content 2 & Content 3\\
Content 1 & Content 2 & Content 3\\
Content 1 & Content 2 & Content 3\\
Content 1 & Content 2 & Content 3\\
Content 1 & Content 2 & Content 3\\
Content 1 & Content 2 & Content 3\\
Content 1 & Content 2 & Content 3\\
Content 1 & Content 2 & Content 3\\
Content 1 & Content 2 & Content 3\\
Content 1 & Content 2 & Content 3\\
Content 1 & Content 2 & Content 3\\
Content 1 & Content 2 & Content 3\\
Content 1 & Content 2 & Content 3\\
Content 1 & Content 2 & Content 3\\
Content 1 & Content 2 & Content 3\\
Content 1 & Content 2 & Content 3\\
Content 1 & Content 2 & Content 3\\
Content 1 & Content 2 & Content 3\\
Content 1 & Content 2 & Content 3\\
Content 1 & Content 2 & Content 3\\
Content 1 & Content 2 & Content 3\\
Content 1 & Content 2 & Content 3\\
Content 1 & Content 2 & Content 3\\
Content 1 & Content 2 & Content 3\\
Content 1 & Content 2 & Content 3\\
Content 1 & Content 2 & Content 3\\
Content 1 & Content 2 & Content 3\\
Content 1 & Content 2 & Content 3\\
Content 1 & Content 2 & Content 3\\
Content 1 & Content 2 & Content 3\\
Content 1 & Content 2 & Content 3\\
Content 1 & Content 2 & Content 3\\
Content 1 & Content 2 & Content 3\\
Content 1 & Content 2 & Content 3\\
Content 1 & Content 2 & Content 3\\
Content 1 & Content 2 & Content 3\\
Content 1 & Content 2 & Content 3\\
Content 1 & Content 2 & Content 3\\
Content 1 & Content 2 & Content 3\\
Content 1 & Content 2 & Content 3\\
Content 1 & Content 2 & Content 3\\
\end{longtable}
\end{document}
请注意,对于此答案中印刷美学的失败,我不承担任何责任,该答案应理解为演示如何实现一组纯粹假设的需求。
也就是说,我不推荐这样做,也不会这样做,但如果必须这样做,你可以这样做。