3

Is there a way to make a table more compact? In term of the spacing between the line smaller, make the table more compact and look more professional.

enter image description here

MY 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
\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}
aan
  • 2,663
  • These is some vertical white space between a line of text and a horizontal line since you used \cmidrule from the booktabs package. This (and the other lines from said package) comes with a little bit of white space around them to prevent overlapping with the text. You can see the difference if you replace one of the \cmidrule commands with a \cline. With the latter command, there will be less space between teh text and the line, making the table look more cramped. – leandriis Feb 11 '20 at 22:02
  • 1
    Personally, I'd try to rearrange the table a bit and entirely get rid of the \cmidrule commands. – leandriis Feb 11 '20 at 22:03
  • 2
    What dies the word "Difference" in the first and otherwise empty column stand for? Couldn't one just move this information into the caption? Please also make sure that you correct the table-format according to the entries in your table. Using table-format=-1.5 as currently will result in overfull box warnings and a slightly off alignment of the corresponding column(s). – leandriis Feb 11 '20 at 22:05
  • @leandriis, thanks. I tried change from \cmidrule to \cline, it seemed the text a bit overlap, and tooo cramped. Very hard to make decision. – aan Feb 11 '20 at 22:06
  • That's why I'd suggest using just the \toprule, \midrule below the headings and the \bottomrule below the table. – leandriis Feb 11 '20 at 22:07
  • I agree with @leandriis: Bring the word "difference to the top line of the now-second column or remove it all together. – Oleg Lobachev Feb 11 '20 at 22:21
  • @OlegLobachev can you do an aswer, i could not get your meaning – aan Feb 11 '20 at 22:39
  • @aan: https://tex.stackexchange.com/a/528029/142180 already did it. – Oleg Lobachev Feb 12 '20 at 20:20

2 Answers2

3

I'd remove all \cmidrule commands. Also, “Difference” seems to apply to all items, so its place is in the table header. Also I'd use the simpler tabular* environment, no need for the complications of tabularx.

I removed the last \multirow, which adds nothing to clarity: the blank will be easily interpreted by the reader as a cell containing the previous value.

Note Std\. Deviation and Std.\ Error, in order to avoid end-of-sentence space after the period. It could also be Std\@. Error, if you prefer.

The two S columns should be declared with table-format=3.4 and table-format=1.3 respectively. The minus sign is taken care of by the three digit entry for the variance. Had the variance less than 100, the format should be -1.4 (because the minus sign is wider than a digit).

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

enter image description here

egreg
  • 1,121,712
  • thanks. Very well done table. One question, how to you move Difference* to be placed on left, and not centre now? – aan Feb 12 '20 at 01:59
  • @aan \thead[l]{Difference\tnote{*}} & – egreg Feb 12 '20 at 09:00
  • Thanks. \multicolumn{2}{c}{\thead[l]{Difference\tnote{*}}} & {\thead{Statistic}}& {\thead{Std.\ Error}} \\ it seemed not working. – aan Feb 12 '20 at 10:07
  • @egreyg, tanks It working with {\thead[l]{Difference. I deleted the multicolumn, is my mistake – aan Feb 12 '20 at 10:11
1

My main suggestion is that you get rid of all \cmidrule directives. Optionally, insert a bit of whitespace after every second or third row via an \addlinespace instruction.

Unless it's somehow vital to show 4 decimal digits in the "Statistic" column, I'd recommend showing just 3 decimal digits. siunitx provides some nice facilities for rounding numbers.

enter image description here

\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}
Mico
  • 506,678