表格宽度相等

表格宽度相等

我正在使用表格方法来创建表格。但是,我注意到列的宽度并不相等,如下图所示。如何使它们相等?

在此处输入图片描述

\begin{table}\centering
\begin{tabular}{l c c c c c c c c c c}
\toprule
    & \multicolumn{5}{c}{Evaluate on complete ground truth} & \multicolumn{5}{c}{Evaluate on truncated} \\ 
    \cmidrule(l{2pt}r{2pt}){2-6} \cmidrule(l{2pt}r{2pt}){7-11}
    & 0s & 1s & 2s & 3s & 4s & 0s & 1s & 2s & 3s & 4s \\
    \midrule
Multi-Task Net & 1 & 2 & 3 & 4 & 5 & 0s & 1s & 2s & 3s & 4s \\
CNN & 71.3 & & & & & & 23.9 & 30.3 & & \\
Keypoints & 55.6 & & & & & & 10.0 & 15.2 & & \\
JAAD & 68.3 & & & & & & 18.3 & 24.9 & & \\
\midrule
CNN LSTM & 68.3 & & & & & & 18.3 & 24.9 & & \\
Keypoints LSTM & 68.3 & & & & & & 18.3 & 24.9 & & \\
3D CNN & 68.3 & & & & & & 18.3 & 24.9 & & \\
\bottomrule
\end{tabular}
\caption{Foo matter}
\end{table}

答案1

解决方案是tabularx,在 5 列组之间添加一个空列,X以使分隔更清晰:

    \documentclass{article}
    \usepackage{booktabs, tabularx}
    \usepackage{geometry}

    \begin{document}

    \begin{table}\centering
    \begin{tabularx}{\linewidth}{@{}l *{5}{>{\centering\arraybackslash}X} c *{5}{>{\centering\arraybackslash}X} }
    \toprule
        & \multicolumn{5}{c}{Evaluate on complete ground truth} & & \multicolumn{5}{c}{Evaluate on truncated} \\
        \cmidrule(l{2pt}r{2pt}){2-6} \cmidrule(l{2pt}r{2pt}){8-12}
        & 0s & 1s & 2s & 3s & 4s & & 0s & 1s & 2s & 3s & 4s \\
        \midrule
    Multi-Task Net & 1 & 2 & 3 & 4 & 5 & & 0s & 1s & 2s & 3s & 4s \\
    CNN & 71.3 & & & & & & & 23.9 & 30.3 & & \\
    Keypoints & 55.6 & & & & & & & 10.0 & 15.2 & & \\
    JAAD & 68.3 & & & & & & & 18.3 & 24.9 & & \\
    \midrule
    CNN LSTM & 68.3 & & & & & & & 18.3 & 24.9 & & \\
    Keypoints LSTM & 68.3 & & & & & & & 18.3 & 24.9 & & \\
    3D CNN & 68.3 & & & & & & & 18.3 & 24.9 & & \\
    \bottomrule
    \end{tabularx}
    \caption{Foo matter}
    \end{table}

    \end{document} 

在此处输入图片描述

答案2

为了使五列等宽,您有几种选择。以下 MWE 包括其中两种。在这两个示例中,我通过使用换行符或添加另一个共享列标题使多列中的文本变窄。

\documentclass{article}
\usepackage{booktabs}
\usepackage{geometry}

\begin{document}

\begin{table}\centering
\begin{tabular}{l c c c c c c c c c c}
\toprule
& \multicolumn{5}{c}{Evaluate on}\\
    & \multicolumn{5}{c}{complete ground truth} & \multicolumn{5}{c}{Evaluate on truncated} \\ 
    \cmidrule(l{2pt}r{2pt}){2-6} \cmidrule(l{2pt}r{2pt}){7-11}
    & 0s & 1s & 2s & 3s & 4s & 0s & 1s & 2s & 3s & 4s \\
    \midrule
Multi-Task Net & 1 & 2 & 3 & 4 & 5 & 0s & 1s & 2s & 3s & 4s \\
CNN & 71.3 & & & & & & 23.9 & 30.3 & & \\
Keypoints & 55.6 & & & & & & 10.0 & 15.2 & & \\
JAAD & 68.3 & & & & & & 18.3 & 24.9 & & \\
\midrule
CNN LSTM & 68.3 & & & & & & 18.3 & 24.9 & & \\
Keypoints LSTM & 68.3 & & & & & & 18.3 & 24.9 & & \\
3D CNN & 68.3 & & & & & & 18.3 & 24.9 & & \\
\bottomrule
\end{tabular}
\caption{Foo matter}
\end{table}


\begin{table}\centering
\begin{tabular}{l c c c c c c c c c c}
\toprule
& \multicolumn{10}{c}{Evaluate on}\\ \cmidrule(l{2pt}r{2pt}){2-11}
    & \multicolumn{5}{c}{complete ground truth} & \multicolumn{5}{c}{truncated} \\ 
    \cmidrule(l{2pt}r{2pt}){2-6} \cmidrule(l{2pt}r{2pt}){7-11}
    & 0s & 1s & 2s & 3s & 4s & 0s & 1s & 2s & 3s & 4s \\
    \midrule
Multi-Task Net & 1 & 2 & 3 & 4 & 5 & 0s & 1s & 2s & 3s & 4s \\
CNN & 71.3 & & & & & & 23.9 & 30.3 & & \\
Keypoints & 55.6 & & & & & & 10.0 & 15.2 & & \\
JAAD & 68.3 & & & & & & 18.3 & 24.9 & & \\
\midrule
CNN LSTM & 68.3 & & & & & & 18.3 & 24.9 & & \\
Keypoints LSTM & 68.3 & & & & & & 18.3 & 24.9 & & \\
3D CNN & 68.3 & & & & & & 18.3 & 24.9 & & \\
\bottomrule
\end{tabular}
\caption{Foo matter}
\end{table}


\end{document}

在此处输入图片描述

答案3

使用包的解决方案卡路里

\documentclass{scrartcl}             % Article class from KOMA-script
\usepackage{cals}

% Defining shortcuts reduces typing

\let\nc=\nullcell
\let\sc=\spancontent

\makeatletter
\def\tb{\ifx\cals@borderT\relax     % Top border switch (off-on)
    \def\cals@borderT{0pt}
\else \let\cals@borderT\relax\fi}

\def\bb{\ifx\cals@borderB\relax     % Botton border switch (off-on)
    \def\cals@borderB{0pt}
\else \let\cals@borderB\relax\fi}

\def\rb{\ifx\cals@borderR\relax     % Right border switch (off-on)
    \def\cals@borderR{0pt}
\else \let\cals@borderR\relax\fi}

\def\lp{\ifdim\cals@paddingL=0.0pt\relax    % Left padding switch (off-on)
    \cals@setpadding{Ag}
\else \setlength{\cals@paddingL}{0pt}\fi}

\def\rp{\ifdim\cals@paddingR=0.0pt\relax    % Left padding switch (off-on)
    \cals@setpadding{Ag}
\else \setlength{\cals@paddingR}{0pt}\fi}


\makeatother

\begin{document}

\begin{table}\centering
\captionabove{Foo matter}       % KOMA-script internal
\small
\begin{calstable}

\colwidths{{\dimexpr(\columnwidth/30*8)\relax}
            {\dimexpr(\columnwidth/30*2)\relax}
            {\dimexpr(\columnwidth/30*2)\relax}
            {\dimexpr(\columnwidth/30*2)\relax}
            {\dimexpr(\columnwidth/30*2)\relax}
            {\dimexpr(\columnwidth/30*2)\relax}
            {\dimexpr(\columnwidth/30*2)\relax}
            {\dimexpr(\columnwidth/30*2)\relax}
            {\dimexpr(\columnwidth/30*2)\relax}
            {\dimexpr(\columnwidth/30*2)\relax}
            {\dimexpr(\columnwidth/30*2)\relax}
            {\dimexpr(\columnwidth/30*2)\relax}
        }

% Set up the tabular
\makeatletter
\def\cals@framers@width{0.6pt} % Horizontal frame rule  
\def\cals@framecs@width{0pt}   % No vertical frame rule 
\def\cals@bodyrs@width{0.6pt}  % Rule between heading and body
\cals@setpadding{Ag}           % Column separation
\cals@setcellprevdepth{Al}
\def\cals@cs@width{0pt}        % No vertical rules 
\def\cals@rs@width{0.4pt}      % Horizontal rules

% R1 H1
\thead{
\brow
    \lp\cell{}\lp              % Remove tabular left side bearing 
    \nc{ltb}                   % Spanning cells (multicol and multirow equivalent
    \nc{tb}
    \nc{tb}
    \nc{tb}
    \lp\rp\nc{rtb}\alignC\sc{\vfill Evaluate on\\ complete ground truth\strut}\lp
    \cell{}
    \nc{ltb}
    \nc{tb}
    \nc{tb}
    \nc{tb}
    \rp\nc{rtb}\alignC\sc{\vfill Evaluate on truncated\strut}\rp %% Remove tabular right side bearing
\erow
% R2 H2
\brow
    \lp\tb\cell{}\tb\lp
    \alignR\cell{0s}
    \cell{1s}
    \cell{2s}
    \cell{3s}
    \cell{4s}
    \tb\cell{}\tb
    \lp\alignR\cell{0s}
    \cell{1s}
    \cell{2s}
    \cell{3s}
    \rp\cell{4s}\rp
\erow
}
% R3 B1
\brow
    \lp\alignL\cell{Multi-Task Net}\lp
    \alignR\cell{0}
    \cell{1}
    \cell{2}
    \cell{3}
    \cell{4}
    \cell{}
    \cell{0s}
    \cell{1s}
    \cell{2s}
    \cell{3s}
    \rp\cell{4s}\rp
\erow
% R4 B2
\brow
    \lp\tb\alignL\cell{CNN}\lp
    \alignR\cell{71.3}
    \cell{}
    \cell{}
    \cell{}
    \cell{}
    \cell{}
    \cell{}
    \cell{23.9}
    \cell{30.3}
    \cell{}
    \rp\cell{}\rp
\erow
% R5 B3
\brow  
    \lp\alignL\cell{Keypoints}\lp
    \alignR\cell{55.6}
    \cell{}
    \cell{}
    \cell{}
    \cell{}
    \cell{}
    \cell{}
    \cell{10.0}
    \cell{15.2}
    \cell{}
    \rp\cell{}\rp
\erow
% R6 B4
\brow
    \lp\alignL\cell{JAAD}\lp
    \alignR\cell{68.3}
    \cell{}
    \cell{}
    \cell{}
    \cell{}
    \cell{}
    \cell{}
    \cell{18.3 }
    \cell{24.9}
    \cell{}
    \rp\cell{}\rp
\erow
% R7 B5
\brow
    \lp\alignL\cell{}\lp
    \alignR\cell{}
    \cell{}
    \cell{}
    \cell{}
    \cell{}
    \cell{}
    \cell{}
    \cell{}
    \cell{}
    \cell{}
    \rp\cell{}\rp
\erow
% R8 B6
\brow
    \lp\alignL\cell{CNN LSTM}\lp
    \alignR\cell{68.3}
    \cell{}
    \cell{}
    \cell{}
    \cell{}
    \cell{}
    \cell{}
    \cell{18.3}
    \cell{24.9}
    \cell{}
    \rp\cell{}\rp
\erow
% R9 B7
\brow
    \lp\alignL\cell{Keypoints LSTM}\lp
    \alignR\cell{68.3}
    \cell{}
    \cell{}
    \cell{}
    \cell{}
    \cell{}
    \cell{}
    \cell{18.3}
    \cell{24.9}
    \cell{}
    \rp\cell{}\rp
\erow
% % R10 B8
\brow
    \lp\alignL\cell{3D CNN}\lp
    \alignR\cell{68.3}
    \cell{}
    \cell{}
    \cell{}
    \cell{}
    \cell{}
    \cell{}
    \cell{18.3}
    \cell{24.9}
    \cell{}
    \rp\cell{}\rp
\erow
\makeatother
\end{calstable}\par
\end{table}

\end{document} 

在此处输入图片描述

相关内容