长桌垂直列分隔符

长桌垂直列分隔符

我有一个相当复杂的longtable设计,我想添加白色列分隔符。我可以使用黑色分隔符添加,|但线条的位置似乎也不理想。

在此处输入图片描述

\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\linewidth}%
\kern-\linewidth}

\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}

\setlength\LTcapwidth{\textwidth}
\setlength\LTleft{0pt}
\setlength\LTright{0pt}
\begin{longtable}{@{\extracolsep{\fill}}=C|+C|+C@{}}
\rowcolor{Blue} 
\rowstyle{\color{white}}
A & B & C \\
1 & 2 & 3 \\
4 & 5 & 6 \\
7 & 8 & 9 \\
\end{longtable}

\end{document}

理想情况下,我希望表格看起来像这样:

在此处输入图片描述

答案1

只需将新的列类型重新定义C为:

\newcolumntype{C}{>{\rowfont\centering\arraybackslash}p{\dimexpr.33\textwidth-2\tabcolsep}}

平均能量损失

\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\linewidth}%
\kern-\linewidth}

\newcolumntype{+}{% adds the current row style to the next column
  >{\@rowstyle}%
}
\newcolumntype{C}{>{\rowfont\centering\arraybackslash}p{\dimexpr.33\textwidth-2\tabcolsep}}

\let\oldlongtable\longtable
\let\endoldlongtable\endlongtable
\renewenvironment{longtable}{\rowcolors{2}{light-gray}{Gray}\oldlongtable} {
\endoldlongtable}

\begin{document}

\setlength\LTcapwidth{\textwidth}
\setlength\LTleft{0pt}
\setlength\LTright{0pt}
\begin{longtable}{@{\extracolsep{\fill}}=C|+C|+C@{}}
\rowcolor{Blue}
\rowstyle{\color{white}}
A & B & C \\
1 & 2 & 3 \\
4 & 5 & 6 \\
7 & 8 & 9 \\
\end{longtable}

\end{document} 

输出:

在此处输入图片描述


编辑

如果要将其概括为未定义的列数,则可以用以下内容替换该定义

\newcolumntype{C}[1]{>{\rowfont\centering\arraybackslash}p{\dimexpr\textwidth/#1-2\tabcolsep}}

它将列数作为参数。

因此,就你的情况而言,你必须写

\begin{longtable}{@{\extracolsep{\fill}}=C{3}|+C{3}|+C{3}@{}}

相关内容