调整表格大小

调整表格大小

我想创建一个表格,但有两个问题。首先,表格太大了。第二个问题是左侧第一个单元格中有一条垂直线。如何让表格变小并位于页面中央,以及如何删除该垂直线?

\documentclass{article}

% Language setting
% Replace `english' with e.g. `spanish' to change the document language
\usepackage[english]{babel}
\usepackage{soul}
\usepackage{longtable}
\pagestyle{empty}


% Set page size and margins
% Replace `letterpaper' with `a4paper' for UK/EU standard size
\usepackage[letterpaper,top=2cm,bottom=2cm,left=3cm,right=3cm,marginparwidth=1.75cm]{geometry}

% Useful packages
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{multirow}
\usepackage[colorlinks=true, allcolors=blue]{hyperref}

\begin{document}

\begin{tabular}{|l|l|l|l|l|l|l|l|l|l|l|l|l|l|l|l|l|l|}\hline
    \multicolumn{2}{|l|}{\multirow{2}{*}{Models}} & \multicolumn{4}{|l|}{DR(eye)VE}  & \multicolumn{4}{|l|}{DR(eye)VE} & \multicolumn{4}{|l|}{DR(eye)VE} & \multicolumn{4}{|l|}{DR(eye)VE}  \\ \cline{3-18}
    && CC & KLD & SIM & NSS &CC & KLD & SIM & NSS &CC & KLD & SIM & NSS &CC & KLD & SIM & NSS  \\ \cline{2-18}

\end{tabular}

\end{document}

答案1

您可以将字体大小设置为\small并减少列分隔符,tabularray易于使用。

\documentclass{article}
\pagestyle{empty}
\usepackage[letterpaper,top=2cm,bottom=2cm,left=3cm,right=3cm,marginparwidth=1.75cm]{geometry}
\usepackage{tabularray}
\begin{document}
\begin{table}
\caption{title}
\begin{tblr}
{
colspec            = {*{17}{Q[co=-1,c,m]}},
hlines,
vlines,
cells              = {cmd=\small},
columns            = {colsep=0pt},
cell{1}{2,6,10,14} = {c=4}{},
cell{1}{1}         = {r=2}{},
}
Models & DR(eye)VE &     &     &     & DR(eye)VE &     &     &     & DR(eye)VE &     &     &     & DR(eye)VE &     &     &     \\
       & CC        & KLD & SIM & NSS & CC        & KLD & SIM & NSS & CC        & KLD & SIM & NSS & CC        & KLD & SIM & NSS \\
\end{tblr}
\end{table}
\end{document}

在此处输入图片描述

答案2

为了完整起见,这里有一个tabularx基于 的解决方案,目标宽度为\textwidth

在此处输入图片描述

\documentclass{article}
\usepackage[english]{babel}
\pagestyle{empty}
\usepackage[letterpaper,vmargin=2cm,hmargin=3cm,
            marginparwidth=1.75cm]{geometry}
\usepackage{multirow,tabularx,ragged2e}
\newcolumntype{C}{>{\Centering}X} % centered version of `X` col. type


\begin{document}

\begingroup % localize scope of next two instructions
\setlength\tabcolsep{1pt} % default: 6pt
\setlength\extrarowheight{2pt} % for a less-cramped "look"

\noindent
\begin{tabularx}{\textwidth}{@{} l @{\hspace{3pt}} | *{16}{C|} }
\cline{2-17}
\multirow{2}{*}{Models}
  & \multicolumn{4}{c|}{DR(eye)VE} & \multicolumn{4}{c|}{DR(eye)VE} 
  & \multicolumn{4}{c|}{DR(eye)VE} & \multicolumn{4}{c|}{DR(eye)VE} \\ 
\cline{2-17}
  & CC & KLD & SIM & NSS & CC & KLD & SIM & NSS 
  & CC & KLD & SIM & NSS & CC & KLD & SIM & NSS \\ 
\cline{2-17}
\end{tabularx}

\endgroup

\end{document}

相关内容