I am using longtable to draw a table that spans a few pages. I also added code to alternate colors for rows in the table.
- Is there a way to colorize the first row with a different color?
- How can I ensure that the caption string is not colorized?
My MWE is below
\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}
Best Answer
You can change row colour with
\rowcolor{}
for the header rows and use\hiderowcolors
and\showrowcolors
to avoid colouring the caption.For example:
Note that I take no responsibility for failures of typographical aesthetics in this answer which should be understood as demonstrating how to implement a purely hypothetical set of desiderata.
That is, I don't recommend this and wouldn't do it, but if you must, you can.