有没有办法让表格变得更紧凑?

有没有办法让表格变得更紧凑?

有没有办法让表格更紧凑?通过缩小行间距,让表格更紧凑,看起来更专业。

在此处输入图片描述

我的妈妈:

\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
\sisetup{table-number-alignment=center}
    \begin{tabularx}{\textwidth}{l>{\raggedright\arraybackslash}XcS[table-format=-1.5]S[table-format=1.5]}
    \toprule
    & & & {\thead{Statistic}}& {\thead{Std. Error}} \\
\midrule
    \multirow{18}{*}{Difference\tnote{*}} & Mean
    & & 43.3329 & 5.238 \\
\cmidrule{2-5}
    & \multirow{2.4}{=}{95\% Confidence Interval for Mean} & Lower Bound & 31.4839 & \\
\cmidrule{3-5}
    & & Upper Bound & \ 55.1818 \\
\cmidrule{2-5}
    & 5\% Trimmed Mean & & 43.3857 \\
\cmidrule{2-5}
    & Median & & 45.2381 \\
\cmidrule{2-5}
    & Variance & & 274.3570 \\
\cmidrule{2-5}
    & Std. Deviation & & 16.5637 \\
\cmidrule{2-5}
    & Minimum & & 19.0476 \\
\cmidrule{2-5}    
    & Maximum & & 66.6667 \\
\cmidrule{2-5} 
    & Range & & 47.6190 \\
\cmidrule{2-5} 
    & Interquartile Range & & 30.9512 \\
\bottomrule
    \end{tabularx}
\end{table}




\end{document}

答案1

我会删除所有\cmidrule命令。另外,“差异”似乎适用于所有项目,因此它的位置在表头中。另外我会使用更简单的tabular*环境,不需要复杂的tabularx

我删除了最后一个\multirow,但这并没有增加清晰度:读者很容易将空白部分解释为包含前一个值的单元格。

注意Std\. DeviationStd.\ Error,以避免句号后出现句末空格。Std\@. Error如果您愿意,也可以使用 。

S列应分别用table-format=3.4和声明table-format=1.3。方差的三位数条目负责处理减号。如果方差小于 100,格式应为-1.4(因为减号比一位数字宽)。

\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}[!htp]

\begin{threeparttable}

\caption{Whatever}

\begin{tabular*}{\textwidth}{
  @{\extracolsep{\fill}}
  l
  l
  S[table-format=3.4]
  S[table-format=1.3]
}
\toprule
\multicolumn{2}{c}{\thead{Difference\tnote{*}}} & {\thead{Statistic}}& {\thead{Std.\ Error}} \\
\midrule
Mean                              &             &  43.3329 & 5.238 \\
95\% Confidence Interval for Mean & Lower Bound &  31.4839 & \\
                                  & Upper Bound &  55.1818 & \\
5\% Trimmed Mean                  &             &  43.3857 & \\
Median                            &             &  45.2381 & \\
Variance                          &             & 274.3570 & \\
Std.\ Deviation                   &             &  16.5637 & \\
Minimum                           &             &  19.0476 & \\
Maximum                           &             &  66.6667 & \\
Range                             &             &  47.6190 & \\
Interquartile Range               &             &  30.9512 & \\
Skewness                          &             &  -0.1046 & 0.687 \\
Kurtosis                          &             &  -1.4128 & 1.334 \\
\bottomrule
\end{tabular*}

\begin{tablenotes}
\item[*] Something explaining what's going on.
\end{tablenotes}

\end{threeparttable}

\end{table}

\end{document}

在此处输入图片描述

答案2

我的主要建议是删除所有\cmidrule指令。或者,通过指令在每隔两行或三行后插入一点空格\addlinespace

除非在“统计”列中显示 4 位小数非常重要,否则我建议只显示 3 位小数。siunitx为四舍五入数字提供了一些不错的功能。

在此处输入图片描述

\documentclass[12pt,oneside]{book}

\usepackage{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 % superfluous
%\sisetup{table-number-alignment=center} % that's the default
\begin{tabularx}{\textwidth}{@{} 
          l 
          >{\raggedright\arraybackslash}X 
          l
          S[table-format=3.3,
            round-mode=places,round-precision=3]
          S[table-format=1.3] @{}}
\toprule
    & & & {\thead{Statistic}}& {\thead{Std.\ Error}} \\
\midrule
\multirow{13}{*}{Difference\tnote{*}} 
    & Mean & & 43.3329 & 5.238 \\
    & \multirow{2}{=}{95\% Conf.\ Interval for Mean} & Lower Bound & 31.4839 \\
\cmidrule(lr){3-4}
    & & Upper Bound & 55.1818 \\
\addlinespace
    & 5\% Trimmed Mean & & 43.3857 \\
    & Median & & 45.2381 \\
\addlinespace
    & Variance & & 274.3570 \\
    & Std.\ Deviation & & 16.5637 \\
\addlinespace
    & Minimum & & 19.0476 \\  
    & Maximum & & 66.6667 \\
\addlinespace 
    & Range & & 47.6190 \\
    & Interquartile Range & & 30.9512 \\
\bottomrule
\end{tabularx}
\end{table}

\end{document}

相关内容