如何刪除具有兩個表的表格環境中列之間的空格?

如何刪除具有兩個表的表格環境中列之間的空格?

在下面的範例中,我無法刪除右側表格中的空格:

\documentclass[runningheads]{llncs}
%
\usepackage{subcaption}
\usepackage{amssymb}
\usepackage{booktabs}
\usepackage{tabularx}
\usepackage{amsmath,array,booktabs}
%\UseTblrLibrary{amsmath, booktabs, counter}
\newtheorem{prop}{proposition}
\setlength\extrarowheight{5pt} % for a less cramped "look"
\newcommand\mc[7]{\multicolumn{1}{c}{#1}} % handy shortcut macro
\begin{document}
\begin{table}[]
\caption{Timetable and distance matrix}
\label{tab:example_7}
\begin{tabular}{@{}llll@{}}
\multicolumn{3}{c}{Timetable}\\
\toprule
u & $t_i$  & $l_i$ & $s_i$\\ \midrule
0 & 0.0  & $90 $  & 0.0 \\
7 & 8.0& 1.15   & 1.0  \\
5 & 8.5& 8.75   & 7.0  \\
N & 0.0& $90 $  & 0.0  \\ \bottomrule
\end{tabular}
\qquad
\begin{tabular}{@{}lllll@{}}
\multicolumn{3}{c}{Distance Matrix}\\
\toprule
u & 0 & 7 & 5 & Y \\ \midrule
0 & 0 & 7 & 8 & 0 \\
7 & 1 & 0 & 5 & 1   \\
5 & 8 & 2 & 0 & 8   \\
N & 0 & 7 & 8 & 0   \\ \bottomrule
\end{tabular}
\end{table}
\end{document}

我見過一些例子,例如刪除表格環境中 \pm 欄位之間的額外空格?,但它們適用於不同的環境。有人可以幫助我理解我所缺少的嗎?謝謝。

答案1

您想要\multicolumn{4}{@{}c@{}}{...}在第一個表和\multicolumn{5}{@{}c@{}}{...}第二個表。

我不會使用 ,而是\extrarowheight增加特定表的列間空間。

中心對齊似乎更合適,但這是一個品味問題。

\documentclass[runningheads]{llncs}
\usepackage{booktabs}

\begin{document}

\begin{table}[htp]
\centering

\caption{Timetable and distance matrix}
\label{tab:example_7}

\setlength{\tabcolsep}{9pt}

\begin{tabular}{@{}cccc@{}}
\multicolumn{4}{@{}c@{}}{Timetable}\\
\toprule
u & $t_i$  & $l_i$ & $s_i$ \\
\midrule
0 & 0.0 &  90  & 0.0 \\
7 & 8.0 & 1.15 & 1.0 \\
5 & 8.5 & 8.75 & 7.0 \\
N & 0.0 &  90  & 0.0 \\
\bottomrule
\end{tabular}\qquad
\begin{tabular}{@{}ccccc@{}}
\multicolumn{5}{@{}c@{}}{Distance Matrix}\\
\toprule
u & 0 & 7 & 5 & Y \\
\midrule
0 & 0 & 7 & 8 & 0 \\
7 & 1 & 0 & 5 & 1 \\
5 & 8 & 2 & 0 & 8 \\
N & 0 & 7 & 8 & 0 \\
\bottomrule
\end{tabular}

\end{table}

\end{document}

在此輸入影像描述

重要的放在一邊。
您的定義\mc有一個嚴重的拼字錯誤:它不應該有[7],但是[1]

答案2

文檔類別為 ; 的值llncs設定了一個小得離譜的值;這是控制類似環境中列間空白數量的參數。在大多數其他文檔類別中,預設值為。我的主要建議是您將 的值設為(或更大)。1.4pt\tabcolseptabular\tabcolsep6pt5pt\tabcolsep

請注意,指令的第一個參數\multicolumn不應為 3,而應分別為 4 和 5。為什麼?您希望標題跨越所有列,不是嗎?而且,第二個參數不應該是c,而是@{}c@{},因為您可能不希望兩側都有空白填充。

最後,由於您使用的是套件的畫線宏booktabs,因此無需更改 的預設值\extrarowheight

在此輸入影像描述

\documentclass{llncs}
\usepackage{booktabs} % for well-spaced horizontal rules

\begin{document}

\begin{table}
\caption{Timetable and distance matrix}
\label{tab:example_7}
\setlength\tabcolsep{5pt} % default: 1.4pt [!]
\centering

\begin{tabular}{@{}llll @{}}
\multicolumn{4}{@{}c@{}}{Timetable}\\
\toprule
u & $t_i$ & $l_i$ & $s_i$ \\ \midrule
0 & 0.0  & $90 $  & 0.0   \\
7 & 8.0  & 1.15   & 1.0   \\
5 & 8.5  & 8.75   & 7.0   \\
N & 0.0  & $90 $  & 0.0   \\ \bottomrule
\end{tabular}
\qquad
\begin{tabular}{@{} lllll @{}}
\multicolumn{5}{@{}c@{}}{Distance matrix}\\
\toprule
u & 0 & 7 & 5 & Y \\ \midrule
0 & 0 & 7 & 8 & 0 \\
7 & 1 & 0 & 5 & 1 \\
5 & 8 & 2 & 0 & 8 \\
N & 0 & 7 & 8 & 0 \\ \bottomrule
\end{tabular}
\end{table}

\end{document}

答案3

大概\multicolumn{3}{c}{Distance Matrix}\\應該是\multicolumn{5}{l}{Distance Matrix}\\。或者“時間表”和“距離矩陣”應該單獨放在周圍的表格中。

\documentclass[runningheads]{llncs}
%
\usepackage{subcaption}
\usepackage{amssymb}
\usepackage{booktabs}
\usepackage{tabularx}
\usepackage{amsmath,array,booktabs}
%\UseTblrLibrary{amsmath, booktabs, counter}
\newtheorem{prop}{proposition}
\setlength\extrarowheight{5pt} % for a less cramped "look"
\newcommand\mc[7]{\multicolumn{1}{c}{#1}} % handy shortcut macro
\begin{document}
\begin{table}[htbp]%
\caption{Timetable and distance matrix}%
\label{tab:example_7}
\begin{tabular}{@{}llll@{}}
\multicolumn{4}{@{}l@{}}{Timetable}\\
\toprule
u & $t_i$  & $l_i$ & $s_i$\\ \midrule
0 & 0.0  & $90 $  & 0.0 \\
7 & 8.0& 1.15   & 1.0  \\
5 & 8.5& 8.75   & 7.0  \\
N & 0.0& $90 $  & 0.0  \\ \bottomrule
\end{tabular}
\qquad
\begin{tabular}{@{}lllll@{}}
\multicolumn{5}{@{}l@{}}{Distance Matrix}\\
\toprule
u & 0 & 7 & 5 & Y \\ \midrule
0 & 0 & 7 & 8 & 0 \\
7 & 1 & 0 & 5 & 1   \\
5 & 8 & 2 & 0 & 8   \\
N & 0 & 7 & 8 & 0   \\ \bottomrule
\end{tabular}
\end{table}

\newcommand\hp[2]{\vbox{\hphantloop#1\relax\hbox{#2}}}%
\newcommand\hphantloop[1]{%
  \ifx\relax#1\else\hbox{\hphantom{#1}}\expandafter\hphantloop\fi
}%

\begin{table}[htbp]%
\caption{Timetable and distance matrix}%
\label{tab:example_7-1}
\begin{tabular}{@{}c@{}}
%\begin{tabular}{@{}l@{}}
Timetable\\
\toprule
\begin{tabular}[t]{@{}llll@{}}
\hp{{u}{0}{7}{5}{N}}{u} & \hp{{$t_i$}{0.0}{8.0}{8.5}{0.0}}{$t_i$} & \hp{{$l_i$}{$90 $}{1.15}{8.75}{$90$}}{$l_i$} & \hp{{$s_i$}{0.0}{1.0}{7.0}{0.0}}{$s_i$}
\end{tabular}
\\ \midrule
\begin{tabular}[t]{@{}llll@{}}
\hp{{u}{0}{7}{5}{N}}{0} & \hp{{$t_i$}{0.0}{8.0}{8.5}{0.0}}{0.0}   & \hp{{$l_i$}{$90 $}{1.15}{8.75}{$90$}}{$90$}  & \hp{{$s_i$}{0.0}{1.0}{7.0}{0.0}}{0.0} \\
\hp{{u}{0}{7}{5}{N}}{7} & \hp{{$t_i$}{0.0}{8.0}{8.5}{0.0}}{8.0}   & \hp{{$l_i$}{$90 $}{1.15}{8.75}{$90$}}{1.15}  & \hp{{$s_i$}{0.0}{1.0}{7.0}{0.0}}{1.0} \\
\hp{{u}{0}{7}{5}{N}}{5} & \hp{{$t_i$}{0.0}{8.0}{8.5}{0.0}}{8.5}   & \hp{{$l_i$}{$90 $}{1.15}{8.75}{$90$}}{8.75}  & \hp{{$s_i$}{0.0}{1.0}{7.0}{0.0}}{7.0} \\
\hp{{u}{0}{7}{5}{N}}{N} & \hp{{$t_i$}{0.0}{8.0}{8.5}{0.0}}{0.0}   & \hp{{$l_i$}{$90 $}{1.15}{8.75}{$90$}}{$90$}  & \hp{{$s_i$}{0.0}{1.0}{7.0}{0.0}}{0.0}  
\end{tabular}
\\ \bottomrule
\end{tabular}
\qquad
\begin{tabular}{@{}c@{}}
Distance Matrix\\
\toprule
\begin{tabular}[t]{@{}lllll@{}}
\hp{{u}{0}{7}{5}{N}}{u} & \hp{{0}{0}{1}{8}{0}}{0} & \hp{{7}{7}{0}{2}{7}}{7} & \hp{{5}{8}{5}{0}{8}}{5} & \hp{{Y}{0}{1}{8}{0}}{Y}
\end{tabular}
\\ \midrule
\begin{tabular}[t]{@{}lllll@{}}
\hp{{u}{0}{7}{5}{N}}{0} & \hp{{0}{0}{1}{8}{0}}{0} & \hp{{7}{7}{0}{2}{7}}{7} & \hp{{5}{8}{5}{0}{8}}{8} & \hp{{Y}{0}{1}{8}{0}}{0} \\
\hp{{u}{0}{7}{5}{N}}{7} & \hp{{0}{0}{1}{8}{0}}{1} & \hp{{7}{7}{0}{2}{7}}{0} & \hp{{5}{8}{5}{0}{8}}{5} & \hp{{Y}{0}{1}{8}{0}}{1} \\
\hp{{u}{0}{7}{5}{N}}{5} & \hp{{0}{0}{1}{8}{0}}{8} & \hp{{7}{7}{0}{2}{7}}{2} & \hp{{5}{8}{5}{0}{8}}{0} & \hp{{Y}{0}{1}{8}{0}}{8} \\
\hp{{u}{0}{7}{5}{N}}{N} & \hp{{0}{0}{1}{8}{0}}{0} & \hp{{7}{7}{0}{2}{7}}{7} & \hp{{5}{8}{5}{0}{8}}{8} & \hp{{Y}{0}{1}{8}{0}}{0} 
\end{tabular}
\\ \bottomrule
\end{tabular}
\end{table}


\end{document}

在此輸入影像描述

相關內容