有一个类似的问题和解决方案发布这里但是,我无法使用此解决方案,因为我有一张彩色表格,并且给定的解决方案会导致每列之间出现白色间隙。
有没有办法让彩色长表适合页面宽度(包括横向页面)以便保持行颜色?
下面是我当前代码的一个示例:
\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{float}
\usepackage{array}
\usepackage{longtable}
\restylefloat{table}
\definecolor{Gray}{gray}{0.65}
\definecolor{Blue}{RGB}{0,176,240}
\definecolor{light-gray}{gray}{0.90}
% Margins
\topmargin=-0.45in
\evensidemargin=0in
\oddsidemargin=0in
\textwidth=6.5in
\textheight=8.5in
\headsep=0.25in
\linespread{1.1} % Line spacing
\newcommand{\specialcell}[2][c]{\begin{tabular}[#1]{@{}c@{}}#2\end{tabular}}
\newcommand\setrowfont[1]{\noalign{\gdef\rowfont{#1}}}
\gdef\rowfont{}
\makeatletter
\newcommand*{\@rowstyle}{}
\newcommand*{\rowstyle}[1]{% sets the style of the next row
\gdef\@rowstyle{#1}%
\@rowstyle\ignorespaces%
}
\newcolumntype{=}{% resets the row style
>{\gdef\@rowstyle{}}%
}
\newcolumntype{+}{% adds the current row style to the next column
>{\@rowstyle}%
}
\newcolumntype{C}{>{\rowfont}c}
\let\oldlongtable\longtable
\let\endoldlongtable\endlongtable
\renewenvironment{longtable}{\rowcolors{2}{light-gray}{Gray}\oldlongtable} {
\endoldlongtable}
\begin{document}
% Normal
\setlength\LTcapwidth{\textwidth}
\setlength\LTleft{-10cm plus -1fill}
\setlength\LTright{\LTleft}
\begin{longtable}{=C+C+C}
\rowcolor{Blue}
\rowstyle{\color{white}}
A & B & C \\
1 & 2 & 3 \\
4 & 5 & 6 \\
7 & 8 & 9 \\
\end{longtable}
% To page width but has white gaps between columns
\setlength\LTcapwidth{\textwidth}
\setlength\LTleft{0pt}
\setlength\LTright{0pt}
\begin{longtable}{@{\extracolsep{\fill}}=C+C+C}
\rowcolor{Blue}
\rowstyle{\color{white}}
A1 & B1 & C1 \\
1 & 2 & 3 \\
4 & 5 & 6 \\
7 & 8 & 9 \\
\end{longtable}
\end{document}
生成:
答案1
\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{float}
\usepackage{array}
\usepackage{longtable}
\restylefloat{table}
\definecolor{Gray}{gray}{0.65}
\definecolor{Blue}{RGB}{0,176,240}
\definecolor{light-gray}{gray}{0.90}
% Margins
\topmargin=-0.45in
\evensidemargin=0in
\oddsidemargin=0in
\textwidth=6.5in
\textheight=8.5in
\headsep=0.25in
\linespread{1.1} % Line spacing
\newcommand{\specialcell}[2][c]{\begin{tabular}[#1]{@{}c@{}}#2\end{tabular}}
\newcommand\setrowfont[1]{\noalign{\gdef\rowfont{#1}}}
\gdef\rowfont{}
\makeatletter
\newcommand*{\@rowstyle}{}
\newcommand*{\rowstyle}[1]{% sets the style of the next row
\gdef\@rowstyle{#1}%
\@rowstyle\ignorespaces%
}
\newcolumntype{=}{% resets the row style
@{\zz}>{\gdef\@rowstyle{}}%
}
\makeatletter
\def\zz{%
{\let\CT@color\color\CT@row@color\leaders\vrule\hskip\textwidth}%
\kern-\textwidth}
\newcolumntype{+}{% adds the current row style to the next column
>{\@rowstyle}%
}
\newcolumntype{C}{>{\rowfont}c}
\let\oldlongtable\longtable
\let\endoldlongtable\endlongtable
\renewenvironment{longtable}{\rowcolors{2}{light-gray}{Gray}\oldlongtable} {
\endoldlongtable}
\begin{document}
% To page width but has white gaps between columns
\setlength\LTcapwidth{\textwidth}
\setlength\LTleft{0pt}
\setlength\LTright{0pt}
\begin{longtable}{=C@{\extracolsep{\fill}}+C+C@{}}
\rowcolor{Blue}
\rowstyle{\color{white}}
A1 & B1 & C1 \\
1 & 2 & 3 \\
4 & 5 & 6 \\
7 & 8 & 9 \\
\end{longtable}
\end{document}