我正在使用 Nikos Alexandris 提出的方法“如何在 LyX 的长表中应用隔行着色?”
在有限的范围内有效,但阴影行不会填满整个页面宽度。每个单元格都有阴影,但阴影会破坏列线,并且阴影中有间隙。
这是我的示例 tex 代码,用于执行破碎的阴影处理。tex 是自动生成的,因此我仅显示一个简短的表格。实际数据更长,并且通常应该跨越具有重复标题的页面。
\date{\today}
\documentclass[9pt]{article}
\usepackage{graphicx}
\usepackage{longtable}
\usepackage[margin=0.5in]{geometry}
\usepackage{fancyhdr}
\LTchunksize=200
\setlength{\parindent}{0cm}
\title{test}
\author{R}
\setlength{\headheight}{0.4in}
\setlength{\headwidth}{\textwidth}
\usepackage[table]{xcolor}
% define lightgray
\definecolor{lightgray}{gray}{0.9}
% alternate rowcolors for all long-tables
\let\oldlongtable\longtable
\let\endoldlongtable\endlongtable
\renewenvironment{longtable}{\rowcolors{2}{white}{lightgray}\oldlongtable} {
\endoldlongtable}
\begin{document}
\section{Sector}
\begin{longtable}{ @{\extracolsep{\fill}} |l | r | r | r | r | r|}
\hline
{} & Beta & Phys & Phys & Phys & comp \\
Industry Code & {} & {} & {} & {} & {} \endhead
\hline
Materials & 16,365,792 & 13,419,455 & 13,419,455 & 0.00 & -201,593 \\
Goods & 471,925 & 1,110,412 & 1,110,412 & 0.00 & -11,947 \\
Services & 7,122,991 & 8,511,225 & 9,492,570 & -981,345 & -75,117 \\
Banks & 5,078,280 & 6,123,238 & 12,084,671 & -5,961,433 & -69,738 \\
Health & 2,141,346 & 5,059,382 & 5,059,382 & 0.00 & -26,319 \\
Industrials & -6,013,491 & -4,758,346 & 6,036,445 & -10,794,791 & 3,722 \\
row & -4,093,746 & -3,755,730 & 0.00 & -3,755,730 & 45,628 \\
row & -1,753,606 & -1,006,601 & 2,533,792 & -3,540,393 & -18,962 \\
Consumer & 2,227,195 & 2,317,581 & 2,317,581 & 0.00 & -30,632 \\
All & 20,808,544 & 25,160,345 & 54,728,908 & -29,568,563 & nan \\
\hline
\end{longtable}
\end{document}
答案1
colortbl
不太喜欢\extracolsep
。对于单个单元格,你可以摆弄可选的悬垂参数,但对于行来说,这有点困难。
而且,您的桌子不是全宽,因为胶水是通过桌子两侧的胶水来\extracolsep
平衡的。\LTleft
\LTright
如果你把它做成全宽,制作彩色带就容易多了,因为你事先知道它们需要多大:
\documentclass[9pt]{article}
\usepackage{graphicx}
\usepackage{longtable}
\usepackage[margin=0.5in]{geometry}
\usepackage{fancyhdr}
\LTchunksize=200
\setlength{\parindent}{0cm}
\title{test}
\author{R}
\setlength{\headheight}{0.4in}
\setlength{\headwidth}{\textwidth}
\usepackage[table]{xcolor}
% define lightgray
\definecolor{lightgray}{gray}{0.9}
% alternate rowcolors for all long-tables
\let\oldlongtable\longtable
\let\endoldlongtable\endlongtable
%\renewenvironment{longtable}{\rowcolors{2}{white}{lightgray}\oldlongtable} {
%\endoldlongtable}
\def\zza{\global\let\zz\zzb
\fullwidthcolor{lightgray}}%
\def\zzb{\global\let\zz\zza}
\def\fullwidthcolor#1{\color{#1}\leaders\vrule\hskip\textwidth\hskip-\textwidth\kern0pt}
\def\resetLTcolor{\global\let\zz\zza}
\LTleft0pt
\LTright0pt
\begin{document}
\section{Sector}
\resetLTcolor
\begin{longtable}{ @{\zz\extracolsep{\fill}} |l | r | r | r | r | r|}
\hline
\multicolumn{1}{@{\fullwidthcolor{yellow}\extracolsep{\fill}} |l |}{}
& Beta & Phys & Phys & Phys & comp \\
\multicolumn{1}{@{\fullwidthcolor{yellow}\extracolsep{\fill}} |l |}{Industry Code}
& {} & {} & {} & {} & {} \endhead
\hline
Materials & 16,365,792 & 13,419,455 & 13,419,455 & 0.00 & -201,593 \\
Goods & 471,925 & 1,110,412 & 1,110,412 & 0.00 & -11,947 \\
Services & 7,122,991 & 8,511,225 & 9,492,570 & -981,345 & -75,117 \\
Banks & 5,078,280 & 6,123,238 & 12,084,671 & -5,961,433 & -69,738 \\
Health & 2,141,346 & 5,059,382 & 5,059,382 & 0.00 & -26,319 \\
Industrials & -6,013,491 & -4,758,346 & 6,036,445 & -10,794,791 & 3,722 \\
row & -4,093,746 & -3,755,730 & 0.00 & -3,755,730 & 45,628 \\
row & -1,753,606 & -1,006,601 & 2,533,792 & -3,540,393 & -18,962 \\
Consumer & 2,227,195 & 2,317,581 & 2,317,581 & 0.00 & -30,632 \\
All & 20,808,544 & 25,160,345 & 54,728,908 & -29,568,563 & nan \\
\hline
\end{longtable}
\end{document}