在下面的示例中,我想要的是longtable
在每个分页符上添加的页脚行具有与其上方行相反的背景颜色。页脚代码似乎只被评估一次。我猜它存储在一个框中。有没有办法强制longtable
在将代码插入页面之前不评估代码?
附加问题:如果我不在\\
行前添加命令(thickline
, thinline
),我会得到一些“noalign”错误,文档无法编译。这迫使我编写非常丑陋的“修复”代码,即\\[-3.1ex]
,否则我会在表格中得到空行。有没有更优雅的解决方案?
\documentclass{article}\pagestyle{empty}
\usepackage{array, booktabs, longtable, colortbl}
\usepackage[usenames, svgnames]{xcolor}
\usepackage{pgfplots}
\newcounter{curRowNum}
\newcommand\incRowNum{\stepcounter{curRowNum}}
\newcommand{\headcol}{\rowcolor{red!25}}
\newcommand{\rowcol}{\rowcolor{red!10}}
\newcommand{\thickline}{\arrayrulecolor{black}\specialrule{0.1em}{0pt}{0pt}\arrayrulecolor{black}}
\newcommand{\thicklinec}{\arrayrulecolor{purple}\specialrule{0.1em}{0pt}{0pt}\arrayrulecolor{black}}
\begin{document}
\setcounter{curRowNum}{0}
\begin{longtable}[!hc]{>{\incRowNum}c}
\caption{MWE longtable coloring test.}\label{tbl:long_color} \\
\thickline
\headcol \multicolumn{1}{c}{ID} \\
\thickline
\endfirsthead
\caption*{Table \ref {tbl:long_color} - Cont.: MWE longtable coloring test.} \\
\thickline
\headcol \multicolumn{1}{c}{ID} %
\pgfmathparse{isodd(\thecurRowNum)}%
\typeout{[Head] Odd: \pgfmathresult - Row: \thecurRowNum}%
\ifnum1=\pgfmathresult\relax%
\\ \thickline %
\else%
\\ \thicklinec %
\fi%
\endhead
\pgfmathparse{int(isodd(\thecurRowNum))}%
\ifnum1=\pgfmathresult\relax%
\\[-3.1ex] \thickline %
\else%
\\[-3.1ex] \thicklinec \rowcol %
\fi%
\multicolumn{1}{>{\incRowNum}r}{\emph{End}}%
\pgfmathparse{int(isodd(\thecurRowNum))}%
\ifnum1=\pgfmathresult\relax%
\\ \thicklinec %
\else%
\\ \thicklinec %
\fi%
\endfoot
\thecurRowNum \\
\rowcol \thecurRowNum \\
\thecurRowNum \\ \newpage
\rowcol \thecurRowNum \\
\thecurRowNum \\
\rowcol \thecurRowNum \\ \newpage
\thecurRowNum \\
\end{longtable}
\end{document}