如何在具有两个表格的表格环境中删除列之间的空格?

如何在具有两个表格的表格环境中删除列之间的空格?

我无法删除以下示例中右侧表格中的空格:

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

在此处输入图片描述

相关内容