删除表格中行与行之间的垂直间距

删除表格中行与行之间的垂直间距

在此处输入图片描述

抱歉图片模糊了,但应该清楚第一行和第二行之间有垂直空间。我想删除它但不知道原因。粘贴的是下面的代码。

\documentclass{article}
\usepackage{graphicx} % Required for inserting images
\usepackage{rawfonts}

%\usepackage{times,amsmath,epsfig}
\usepackage{epsfig}
\usepackage{fancyhdr}
\usepackage{amsmath}
\DeclareMathOperator*{\argmin}{arg\,min}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{array}
\usepackage{graphicx}
\usepackage{url}
\usepackage{subfigure}
\usepackage{bm}
\usepackage{breqn}
\usepackage{xcolor}
\usepackage{soul}
\usepackage{amssymb}
\usepackage[breaklinks=true,hidelinks]{hyperref}
\usepackage{breakcites}

\usepackage{algorithm}
\usepackage{algpseudocode}
\usepackage{multirow}
\usepackage[justification=centering]{caption}
\usepackage{float}

\usepackage{graphics}

\usepackage{setspace}

\usepackage{xr}
%\externaldocument{supp}

% \doublespacing

%\newcolumntype{P}[1]{>{\centering\arraybackslash}p{#1}}
%\newcolumntype{M}[1]{>{\centering\arraybackslash}m{#1}}

% correct bad hyphenation here


\newcolumntype{P}[1]{>{\centering\arraybackslash}p{#1}}
\newcolumntype{M}[1]{>{\centering\arraybackslash}m{#1}}


\begin{document}

\begin{table*}[h!]
\centering
\caption{Random Table}
\label{tab:main} 
\resizebox{\columnwidth}{!}{%
\begin{tabular}{|M{0.25\linewidth} M{0.1\linewidth} M{0.3\linewidth} M{0.2\linewidth} M{0.2\linewidth} M{0.2\linewidth} M{0.15\linewidth} M{0.2\linewidth} M{0.15\linewidth} M{0.2\linewidth} M{0.15\linewidth}|}
\hline

Dataset & ${n_{a}}$ & {Method} & s2 (\%) & s3 & s4 (\%) &
s5 & s6 & s7 & s8 & {\emph{something}}  \\
\hline

\multirow[c]{6}{*}{jgifosjgs}

& \multirow[c]{3}{*}{jgiosjgs} & gjiosfgjfsi & 5 & 10 & 52 & 3.27 & -086 & 0.03 & 3.9 & 2.01   \\ 
&& ngfiosjgofs & 37 & 3.1 & 73 & 1.85 & 1.31 & -0.01 & 5 & 2.58  \\
&& jgiofsjgfs & 2.6 & 65.4 & 57 & 3.08 & 0.07 & 10 & 9 & 82 \\ \hline
\end{tabular}%
}
\end{table*}
\end{document}


答案1

如果你不拒绝尝试tabularray,那么tabularray是一个不错的选择。

\documentclass{article}
\usepackage[justification=centering]{caption}
\usepackage{tabularray}
\begin{document}
\begin{table}
\caption{Random Table}
\label{tab:main}
\centering
\small
\begin{tblr}
{
rows         = {halign=c},
columns      = {valign=m,co=-1},
columns      = {colsep=0pt},
cell{2}{1,2} = {r=3}{},
hline{1,Z}   = {wd=.08em},
hline{2}     = {wd=.05em},
cell{1}{Z}   = {cmd=\emph},
}
Dataset   & $n_{a}$  & Method      & s2 (\%) & s3   & s4 (\%) & s5   & s6   & s7    & s8  & something \\
jgifosjgs & jgiosjgs & gjiosfgjfsi & 5       & 10   & 52      & 3.27 & -086 & 0.03  & 3.9 & 2.01      \\
          &          & ngfiosjgofs & 37      & 3.1  & 73      & 1.85 & 1.31 & -0.01 & 5   & 2.58      \\
          &          & jgiofsjgfs  & 2.6     & 65.4 & 57      & 3.08 & 0.07 & 10    & 9   & 82        \\
\end{tblr}
\end{table}
\end{document}

在此处输入图片描述

答案2

您需要修复的参数\multirow

不需要\resizebox大锤——只需从固定宽度的列切换到c列,使用\small,并切换到tabular*环境,就可以使表格适合文本块的宽度。

我已经注释了你的序言代码。请尝试简化和精简你的编码实践。

在此处输入图片描述

\documentclass{article}
\usepackage{graphicx} % Required for inserting images
\usepackage{rawfonts}

%\usepackage{times,amsmath,epsfig}
%%%\usepackage{epsfig} % is loaded automatically by graphicx
\usepackage{fancyhdr}
\usepackage{amsmath}
\DeclareMathOperator*{\argmin}{arg\,min}
%%%\usepackage{amsfonts} % is loaded automatically by amssymb
\usepackage{amssymb}
\usepackage{array}
%%%\usepackage{graphicx} % don't load packages more than once
\usepackage{xurl} % 'xurl' is more powerful than 'url' package
%%%\usepackage{subfigure} % is deprecated, use 'subcaption' instead; see also below
\usepackage{bm}
\usepackage{breqn} % are you sure you need this package?
\usepackage{xcolor}
\usepackage{soul}
%%%\usepackage{amssymb} % don't load packages more than once
\usepackage[breaklinks=true,hidelinks]{hyperref}
%%%\usepackage{breakcites} % obsolete

\usepackage{algorithm}
\usepackage{algpseudocode}
\usepackage{multirow}
\usepackage[justification=centering,
            skip=0.333\baselineskip
           ]{caption}
\usepackage{subcaption} % <-- new 
\usepackage{float}

%%%\usepackage{graphics} % is loaded automatically by graphicx

\usepackage{setspace}

\usepackage{xr}
%\externaldocument{supp}

% \doublespacing

%\newcolumntype{P}[1]{>{\centering\arraybackslash}p{#1}}
%\newcolumntype{M}[1]{>{\centering\arraybackslash}m{#1}}

% correct bad hyphenation here

\newcolumntype{P}[1]{>{\centering\arraybackslash}p{#1}}
\newcolumntype{M}[1]{>{\centering\arraybackslash}m{#1}}

\begin{document}

\begin{table*}[h!]
\small % 10% linear reduction of font size
\captionsetup{font=small}
\caption{Random Table}
\label{tab:main} 
%\resizebox{\columnwidth}{!}{%
\setlength\tabcolsep{0pt}
\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}*{11}{c}}
\hline

Dataset & $n_{a}$ & Method & s2 (\%) & s3 & s4 (\%) &
s5 & s6 & s7 & s8 & \emph{something}  \\
\hline

\multirow[c]{3}{*}{jgifosjgs} & 
\multirow[c]{3}{*}{jgiosjgs} & gjiosfgjfsi 
& 5 & 10 & 52 & 3.27 & -086 & 0.03 & 3.9 & 2.01   \\ 
&& ngfiosjgofs & 37 & 3.1 & 73 & 1.85 & 1.31 & -0.01 & 5 & 2.58  \\
&& jgiofsjgfs & 2.6 & 65.4 & 57 & 3.08 & 0.07 & 10 & 9 & 82 \\ 
\hline
\end{tabular*}
%}
\end{table*}
\end{document}

答案3

rawfonts和包epsfig是已有 30 年历史的 LaTeX 2.09 文档兼容层,不适用于 1995 年后编写的文档。

也是breqn一个实验性的软件包,可能会破坏一些东西。graphics之后加载graphicx是无用的。

hyperref应该最后加载。

\begin{table}[h!]不是一个好主意。而且在单列格式中,没有必要table*

调整表格大小是坏的想法。我认为没有必要定义总和大于的列,\textwidth然后再缩小表格。

\documentclass{article}
\usepackage{graphicx} % Required for inserting images
\usepackage{fancyhdr}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{array}
\usepackage{graphicx}
\usepackage{url}
\usepackage{subfigure}
\usepackage{bm}
%\usepackage{breqn}
\usepackage{xcolor}
\usepackage{soul}
\usepackage{breakcites}
\usepackage{algorithm}
\usepackage{algpseudocode}
\usepackage{multirow}
\usepackage[justification=centering]{caption}
%\usepackage{float}
\usepackage{setspace}
\usepackage{xr}

\usepackage{booktabs}
\usepackage{siunitx}

\usepackage[breaklinks=true,hidelinks]{hyperref}

%\externaldocument{supp}

\DeclareMathOperator*{\argmin}{arg\,min}


% \doublespacing

%\newcolumntype{P}[1]{>{\centering\arraybackslash}p{#1}}
%\newcolumntype{M}[1]{>{\centering\arraybackslash}m{#1}}

% correct bad hyphenation here


\newcolumntype{P}[1]{>{\centering\arraybackslash}p{#1}}
\newcolumntype{M}[1]{>{\centering\arraybackslash}m{#1}}


\begin{document}

\begin{table}[htp!]
\centering
\footnotesize

\caption{Random Table}
\label{tab:main}

\setlength{\tabcolsep}{0pt}% leave TeX computing

\begin{tabular*}{\textwidth}{
  @{\extracolsep{\fill}}
  l
  c
  c
  S[table-format=2.1] % s2
  S[table-format=2.1] % s3
  S[table-format=2.0] % s4
  S[table-format=1.2] % s5
  S[table-format=-1.2] % s6
  S[table-format=-1.2] % s7
  S[table-format=1.1] % s8
  S[table-format=2.2] % something
  @{}
}
\toprule

Dataset & ${n_{a}}$ & Method & {s2 (\%)} & {s3} & {s4 (\%)} &
{s5} & {s6} & {s7} & {s8} & {\emph{something}}  \\

\midrule

\multirow[c]{3}{*}{jgifosjgs}

& \multirow[c]{3}{*}{jgiosjgs} & gjiosfgjfsi & 5 & 10 & 52 & 3.27 & -0.86 & 0.03 & 3.9 & 2.01   \\ 
&& ngfiosjgofs & 37 & 3.1 & 73 & 1.85 & 1.31 & -0.01 & 5 & 2.58  \\
&& jgiofsjgfs & 2.6 & 65.4 & 57 & 3.08 & 0.07 & 10 & 9 & 82 \\
\bottomrule

\end{tabular*}

\end{table}
\end{document}

在此处输入图片描述

我怀疑以下做法的实用性\multirow:将这些单元格放在组顶部。我添加了一个示例来说明如何执行此操作。

\begin{tabular*}{\textwidth}{
  @{\extracolsep{\fill}}
  l
  c
  c
  S[table-format=2.1] % s2
  S[table-format=2.1] % s3
  S[table-format=2.0] % s4
  S[table-format=1.2] % s5
  S[table-format=-1.2] % s6
  S[table-format=-1.2] % s7
  S[table-format=1.1] % s8
  S[table-format=2.2] % something
  @{}
}
\toprule

Dataset & ${n_{a}}$ & Method & {s2 (\%)} & {s3} & {s4 (\%)} &
{s5} & {s6} & {s7} & {s8} & {\emph{something}}  \\

\midrule

jgifosjgs
& jgiosjgs & gjiosfgjfsi & 5 & 10 & 52 & 3.27 & -0.86 & 0.03 & 3.9 & 2.01   \\ 
&& ngfiosjgofs & 37 & 3.1 & 73 & 1.85 & 1.31 & -0.01 & 5 & 2.58  \\
&& jgiofsjgfs & 2.6 & 65.4 & 57 & 3.08 & 0.07 & 10 & 9 & 82 \\

\addlinespace

jgifosjgs
& jgiosjgs & gjiosfgjfsi & 5 & 10 & 52 & 3.27 & -0.86 & 0.03 & 3.9 & 2.01   \\ 
&& ngfiosjgofs & 37 & 3.1 & 73 & 1.85 & 1.31 & -0.01 & 5 & 2.58  \\
&& jgiofsjgfs & 2.6 & 65.4 & 57 & 3.08 & 0.07 & 10 & 9 & 82 \\

\addlinespace

jgifosjgs
& jgiosjgs & gjiosfgjfsi & 5 & 10 & 52 & 3.27 & -0.86 & 0.03 & 3.9 & 2.01   \\ 
&& ngfiosjgofs & 37 & 3.1 & 73 & 1.85 & 1.31 & -0.01 & 5 & 2.58  \\
&& jgiofsjgfs & 2.6 & 65.4 & 57 & 3.08 & 0.07 & 10 & 9 & 82 \\

\bottomrule

\end{tabular*}

在此处输入图片描述

相关内容