长表的问题-15列

长表的问题-15列

我正在尝试创建一个有 15 列的长表 - 但是,它在编译时不能与页面边框正确匹配。

谁能帮我吗?

\documentclass{article}

\RequirePackage[l2tabu,orthodox]{nag}
\usepackage{multirow}
\usepackage{longtable}
\usepackage{chngpage}
\usepackage{colortbl}
\usepackage{xcolor}
\usepackage{longtable}
\usepackage{paracol}
\usepackage{booktabs, makecell, tabularx}
\usepackage{booktabs, multirow}

\begin{document}
\begin{table}
\centering
\caption{Comparison of customers.}
\begin{tabular}{c c ccc ccc ccc ccc ccc}
\multirow{2}{*}{}
&
\multirow{2}{*}{} 
        & \multicolumn{15}{c}{customers}\\
    \cmidrule(lr){3-17}
        &  & \cellcolor{lightgray} 1  & \cellcolor{lightgray} 2  & \cellcolor{lightgray} 3  & \cellcolor{lightgray} 4  & \cellcolor{lightgray} 5  & \cellcolor{lightgray} 6 &
        \cellcolor{lightgray} 7  & \cellcolor{lightgray} 8  & \cellcolor{lightgray} 9  & \cellcolor{lightgray} 10  & \cellcolor{lightgray} 11  & \cellcolor{lightgray} 12 & \cellcolor{lightgray} 13  & \cellcolor{lightgray} 14  &  \cellcolor{lightgray} 15   \\
\multirow{4}{*}{1}  
        & values &
        \cellcolor{orange} 0.64&
        \cellcolor{orange} 0.92 &
        \cellcolor{orange} 0.46 &
        \cellcolor{orange} 0.33 &
        \cellcolor{orange} 0.33& 
        \cellcolor{orange} 0.53 &
        \cellcolor{orange} 0.22 & 
        \cellcolor{orange} 0.82 &
         \cellcolor{orange} 0.521&
         \cellcolor{orange} 0.15& 
         \cellcolor{orange} 0.46  & 
        \cellcolor{orange} 0.46  &
        \cellcolor{orange} 0.54  & 
        \cellcolor{orange} 0.25  & 
        \cellcolor{orange} 0.54\\
\end{tabular}
\label{tab}
\end{table}
\end{document}

提前致谢!

答案1

该表有 17 列,而不是 15 列。

假设您使用 A4 尺寸纸张、2.5 厘米边距、Computer Modern Roman 字体和主字体大小10pt,则以下代码将使表格(刚好)适合文本块内。

我还建议您使用\rowcolor指令,而不是\cellcolor在一行中使用 15 个相邻的指令。

在此处输入图片描述

\documentclass[10pt]{article}
\usepackage[a4paper,margin=2.5cm]{geometry}
\RequirePackage[l2tabu,orthodox]{nag}
\usepackage[table]{xcolor}
\usepackage{booktabs, multirow}

\begin{document}

\begin{table}
\setlength\tabcolsep{4.5pt} % default: 6pt

\centering
\caption{Comparison of customers.} \label{tab}

\smallskip
\begin{tabular}{@{} *{17}{c} }
\toprule
& & \multicolumn{15}{c}{customers}\\
\rowcolor{lightgray}
\cellcolor{white} 
& \cellcolor{white} & 
 1 &  2 &  3 &  4 &  5 & 6 &  7 &  8 &  9 & 10 & 11 & 12 & 13 & 14 & 15 \\
\rowcolor{orange}
\cellcolor{white}\multirow{4}{*}{1} % what's this about??
& \cellcolor{white} values &
 0.64 & 0.92 & 0.46 & 0.33 & 0.33 & 0.53 & 0.22 & 0.82 & 0.521& 0.15 & 0.46 & 0.46 & 0.54 & 0.25 & 0.54 \\
& & b\\
& & c\\
& & d\\
\bottomrule
\end{tabular}
\end{table}
\end{document}

相关内容