如何让表格格式紧凑

如何让表格格式紧凑

我正在使用表格模板代码,但我不太理解代码的含义。我想让表格紧凑,而不是像下面这样空出空间。

在此处输入图片描述

我想要像这样紧凑:

在此处输入图片描述

我不知道我应该在哪里更改此表格格式:

\begin{tabular*}{\textwidth}{
%  @{\hspace{\tabcolsep}\extracolsep{\fill}}  /% so left some space on the Left and right and delete the last row  @{} /%
  @{\extracolsep{\fill}}
  l
  S[table-format=2.2]
  S[table-format=2.2]
  S[table-format=2.2]
  @{}  % can delete and add "@{\hspace{\tabcolsep}\extracolsep{\fill}}" to left some space on the left and right
}

完整 MWE:

\documentclass[12pt,oneside]{book}

\usepackage[showframe]{geometry}
\usepackage{amsmath}
\usepackage{ragged2e}
\usepackage{booktabs, makecell, multirow, tabularx,
            threeparttable, tabulary}
\renewcommand\theadfont{\small\bfseries} % for bold in table using \small
\renewcommand\theadgape{}
\usepackage[svgnames, table]{xcolor}
\usepackage{siunitx} %for table spacing to second row
\usepackage{graphicx}

\usepackage[font=small,
            labelfont={bf,sf}, textfont={sf}, 
            justification=centering]{caption}

\begin{document}



\begin{table}[h!]
\centering
\begin{tabular*}{\textwidth}{
%  @{\hspace{\tabcolsep}\extracolsep{\fill}}  /% so left some space on the Left and right and delete the last row  @{} /%
  @{\extracolsep{\fill}}
  l
  S[table-format=2.2]
  S[table-format=2.2]
  S[table-format=2.2]
  @{}  % can delete and add "@{\hspace{\tabcolsep}\extracolsep{\fill}}" to left some space on the left and right
}
\toprule
{\thead{Stimulus \\ Number}} 
  & {\thead{Class A \\ Sample \\ Number}}
  & {\theadfont N}
  & {\thead{Standard  \\ Deviation \\ (\%)}} \\
\midrule
\textit{Test Case 1}  & 88.57  & 10 & 11.49 \\
\textit{Test Case 2}  & 57.62  & 10 & 13.55 \\
\bottomrule
\end{tabular*}

\end{table}



\end{document}

答案1

在此处输入图片描述

只需删除fill表中的命令并将其替换为@{}

@{\extracolsep{\fill}}
  l
  S[table-format=2.2]
  S[table-format=2.2]
  S[table-format=2.2]
  @{} 

变成

@{}
  l
  S[table-format=2.2]
  S[table-format=2.2]
  S[table-format=2.2]
  @{} 

就是这样!

平均能量损失

\documentclass[12pt,oneside]{book}

\usepackage[showframe]{geometry}
\usepackage{amsmath}

\usepackage{booktabs, makecell}
\renewcommand\theadfont{\small\bfseries} % for bold in table using 
\usepackage[svgnames, table]{xcolor}
\usepackage{siunitx} %for table spacing to second row

\begin{document}

\begin{table}[h!]
\centering 
\begin{tabular*}{0.55\textwidth}{
  @{}
  l
  S[table-format=2.2]
  S[table-format=2.2]
  S[table-format=2.2]
  @{}  
}
\toprule
{\thead{Stimulus \\ Number}} 
  & {\thead{Class A \\ Sample \\ Number}}
  & {\theadfont N}
  & {\thead{Standard  \\ Deviation \\ (\%)}} \\
\midrule
\textit{Test Case 1}  & 88.57  & 10 & 11.49 \\
\textit{Test Case 2}  & 57.62  & 10 & 13.55 \\
\bottomrule
\end{tabular*}
\end{table}

\end{document}

相关内容