Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- \documentclass{article}
- \usepackage{etoolbox}
- \usepackage[table]{xcolor}
- \usepackage{booktabs} % or ctable
- \colorlet{text}{black}
- \colorlet{page}{white}
- \colorlet{tableheadcolor}{orange!30!page}
- % The use of \showrowcolors and \hiderowcolors is an idea from Ulrike
- % Fischer's answer here: <https://tex.stackexchange.com/a/494954/73317>
- \renewcommand{\toprule}{%
- \showrowcolors
- \arrayrulecolor{text}\specialrule{\heavyrulewidth}{\abovetopsep}{0pt}%
- \arrayrulecolor{tableheadcolor}\specialrule{\belowrulesep}{0pt}{0pt}%
- \arrayrulecolor{text}%
- \rowcolor{tableheadcolor}%
- }
- \apptocmd\midrule{\hiderowcolors}{}{\FAILED}
- \makeatletter
- \let\@BTrule@ORI=\@BTrule
- \let\my@BTrule=\@BTrule
- % Modified version of \@BTrule that doesn't do \vskip\@aboverulesep, for use
- % when the corresponding vertical space should be coloured.
- \patchcmd{\my@BTrule}{%
- \ifnum\@lastruleclass=\z@\vskip\@aboverulesep\else
- }{%
- \ifnum\@lastruleclass=\z@\else
- }{}{\FAILED}
- \let\@arraycrORI=\@arraycr
- % The “master counter” hackery is explained in the TeXbook appendix D (Dirty
- % Tricks), pp. 385-386. It is also mentioned in the array.sty implementation
- % notes concerning \@arraycr.
- \renewcommand*{\@arraycr}{%
- % Increase the master counter. This is needed to prevent TeX from
- % prematurely finishing the alignment entry in case \\ was followed by '&'
- % (when the \futurelet from \@ifnextchar causes TeX to read a '&', this
- % finishes the entry unless the master counter has a different value than it
- % had when the entry was started).
- \relax\iffalse{\fi\ifnum 0=`}\fi
- % Each of the two branches takes care of decreasing the master counter.
- \@ifnextchar\midrule
- {\@firstoftwo{\my@endtablehead}}% gobble the following \midrule
- {\my@closebrace@and@arraycrORI}%
- }
- \newcommand*{\my@endtablehead}{%
- \ifnum 0=`{}\fi % the second brace decreases the master counter
- \@arraycrORI[\aboverulesep]% this colours the additional space with the
- % current row color
- \noalign{\global\let\@BTrule\my@BTrule}% temporarily modify \@BTrule
- \midrule
- \noalign{\global\let\@BTrule\@BTrule@ORI}% restore it
- }
- \newcommand*{\my@closebrace@and@arraycrORI}{%
- \ifnum 0=`{}\fi % the second brace decreases the master counter
- \@arraycrORI
- }
- \makeatother
- \rowcolors{1}{tableheadcolor}{tableheadcolor}
- \begin{document}
- \pagecolor{blue!10}
- \begin{tabular}{l}
- a \\
- b \\
- c
- \end{tabular}
- \bigskip
- \begin{tabular}{l}
- \midrule
- \end{tabular}
- \bigskip
- \begin{tabular}{l}
- a \\
- b \\
- c
- \end{tabular}
- \end{document}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement