我无法像在 LaTeX 中预期的那样调整表格标题的间距。
我的表格应该是这样的:
但不幸的是,它在文档中显示如下:
标题不适合页面宽度,标题标签(例如“推荐商品数量”)占据了表格中的一行,因此占用了大量空间。解决方案的一部分是增加标题的高度。
我想尽可能减少表格上的空白,以使其清晰易读并适合页面。
以下是代码:
%Please add the following packages if necessary:
%\usepackage{booktabs, multirow} % for borders and merged ranges
%\usepackage{soul}% for underlines
%\usepackage[table]{xcolor} % for cell colors
%\usepackage{changepage,threeparttable} % for wide tables
%If the table is too wide, replace \begin{table}[!htp]...\end{table} with
%\begin{adjustwidth}{-2.5 cm}{-2.5 cm}\centering\begin{threeparttable}[!htb]...\end{threeparttable}\end{adjustwidth}
\begin{table}[!htp]\centering
\caption{Generated by Spread-LaTeX}\label{tab: }
\scriptsize
\begin{tabular}{lrrrrrrrr}\toprule
Execution environment &Number of recommended items &Dataset size &Total API endpoint execution time (seconds) &Endpoint execution latency &Recommendation execution &Data processing time (seconds) &Recommender algorithm execution time (seconds) \\\midrule
Local (API) &3 &20000263 &50.05549 &0.01421 &50.04128 &46.52477 &3.51651 \\
Local (Algorithm only) &3 &20000263 & & &53.21693 &48.71163 &4.50530 \\
Heroku (API) &3 &20000263 &MEMORY OVERFLOW & & & & \\
PAW (API) &3 &20000263 &MEMORY OVERFLOW & & & & \\
Local (API) &5 &20000263 &48.26075 &0.00957 &48.25118 &44.64684 &3.60434 \\
Local (Algorithm only) &5 &20000263 & & &64.97844 &60.10595 &4.87248 \\
Heroku (API) &5 &20000263 &MEMORY OVERFLOW & & & & \\
PAW (API) &5 &20000263 &MEMORY OVERFLOW & & & & \\
Local (API) &10 &20000263 &43.31767 &0.01661 &43.30106 &39.85879 &3.44227 \\
Local (Algorithm only) &10 &20000263 & & &44.16319 &40.60699 &3.55620 \\
Heroku (API) &10 &20000263 &MEMORY OVERFLOW & & & & \\
PAW (API) &10 &20000263 &MEMORY OVERFLOW & & & & \\
\multicolumn{1}{c}{AVERAGE} &45.78921 &0.01309 &50.78216 &46.78604 &3.99612 \\
& &STDV &3.4952824449691047 &0.00497738403016791 &8.855024886265406 &8.2442634610736 &0.6482773532436392 \\
\bottomrule
\end{tabular}
\end{table}
谢谢
答案1
即使在标准 LaTeX 布局中,您也可以放进表格,但您必须删除那些冗长的标题和长数字。例如,我用一些符号替换了标题,并在表格底部添加了每个符号代表什么的解释。我认为您不需要 15 位小数。最后,每个执行环境的数据大小似乎都相同,我会将其移动到其他地方(注释或标题)以避免重复。
将所有内容放在一起的一种方法是使用threeparttable
。它有助于将表格环境分成三个部分:标题、表格本身和注释。siunitx
将长数字四舍五入到小数点后几位;您仍然可以将数字保留在表格中并找出最适合您的选项。
\documentclass{article}
\usepackage{mathtools}
\usepackage{threeparttable}
\usepackage{booktabs}
\usepackage{siunitx}
\sisetup{
round-mode = places,
round-precision = 2,
minimum-decimal-digits = 1,
}
\begin{document}
\begin{table}[!htp]\centering
\small
\begin{threeparttable}
\caption{Generated by Spread-LaTeX}
\label{tab: }
\begin{tabular}{
l
r
S[table-format=2.1, round-precision = 1]
S[table-format=1.3, round-precision = 4]
*2{S[table-format=2.1, round-precision = 1]}
S[table-format=1.2, round-precision = 2]
}
\toprule
$E$\textsubscript{ENV}\tnote{1}
& $N$\textsubscript{REC}\tnote{2} % etc.
& {$T$\tnote{3}}
& {$L$\tnote{4}}
& {$R$\tnote{5}}
& {$P$\tnote{6}}
& {$A$\tnote{7}} \\
\midrule
Local (API) & 3 & 50.05549 & 0.01421 & 50.04128 & 46.52477 & 3.51651 \\
Local (Algorithm only) & 3 & {--} & {--} & 53.21693 & 48.71163 & 4.50530 \\
Heroku (API) & 3 & {MO} & {--} & {--} & {--} & {--} \\
PAW (API) & 3 & {MO} & {--} & {--} & {--} & {--} \\
Local (API) & 5 & 48.26075 & 0.00957 & 48.25118 & 44.64684 & 3.60434 \\
Local (Algorithm only) & 5 & {--} & {--} & 64.97844 & 60.10595 & 4.87248 \\
Heroku (API) & 5 & {MO} & {--} & {--} & {--} & {--} \\
PAW (API) & 5 & {MO} & {--} & {--} & {--} & {--} \\
Local (API) & 10 & 43.31767 & 0.01661 & 43.30106 & 39.85879 & 3.44227 \\
Local (Algorithm only) & 10 & {--} & {--} & 44.16319 & 40.60699 & 3.55620 \\
Heroku (API) & 10 & {MO} & {--} & {--} & {--} & {--} \\
PAW (API) & 10 & {MO} & {--} & {--} & {--} & {--} \\
\midrule[\cmidrulewidth]
\multicolumn{2}{r}{AVERAGE} & 45.78921 & 0.01309 & 50.78216 & 46.78604 & 3.99612 \\
\multicolumn{2}{r}{STDV} & 3.4952824449691047 & 0.00497738403016791 & 8.855024886265406 & 8.2442634610736 & 0.6482773532436392 \\
\bottomrule
\end{tabular}
Data size: \num[minimum-decimal-digits=0,round-precision=0]{20000263},\quad
MO: Memory Overflow\par
\medskip
\tnote{1}~Execution environment,\quad%
\tnote{2}~Number of recommended items,\quad%
\tnote{3}~Total API endpoint execution time (seconds),\quad%
\tnote{4}~Endpoint execution latency,\quad%
\tnote{5}~Recommendation execution,\quad%
\tnote{6}~Data processing time (seconds),\quad%
\tnote{7}~Recommender algorithm execution time (seconds)
\end{threeparttable}
\end{table}
\end{document}
答案2
欢迎,我为你准备了一个开始
\documentclass[12pt, A4]{article}
\usepackage[utf8]{inputenc}
\usepackage{fourier}
\usepackage{array}
\usepackage{makecell}
\usepackage{adjustbox}
\renewcommand\theadalign{bc}
\renewcommand\theadfont{\bfseries}
\renewcommand\theadgape{\Gape[4pt]}
\renewcommand\cellgape{\Gape[4pt]}
\begin{document}
\setlength\extrarowheight{3pt}
\begin{table}[ht]
\centering
\begin{adjustbox}{width=1\textwidth}
\small
\begin{tabular}{|c|clc|c|c|c|c|c|}
\hline
\thead{Execution \\ environment} & \thead{Number of \\ recomended items} & \thead{Data size} & \thead{Total endpoint} & \thead{execution time\\ (seconds)} & \thead{Endpoint execution} & \thead{Data processing \\time} & \thead{Recommender \\ Algorith time \\ (seconds)} \\ \hline
Local (API) &3 &20000263 &50.05549 &0.01421 &50.04128 &46.52477 &3.51651 \\
Local (Algorithm only) &3 &20000263 & & &53.21693 &48.71163 &4.50530 \\
Heroku (API) &3 &20000263 &MEMORY OVERFLOW & & & & \\
PAW (API) &3 &20000263 &MEMORY OVERFLOW & & & & \\
Local (API) &5 &20000263 &48.26075 &0.00957 &48.25118 &44.64684 &3.60434 \\
Local (Algorithm only) &5 &20000263 & & &64.97844 &60.10595 &4.87248 \\
Heroku (API) &5 &20000263 &MEMORY OVERFLOW & & & & \\
PAW (API) &5 &20000263 &MEMORY OVERFLOW & & & & \\
Local (API) &10 &20000263 &43.31767 &0.01661 &43.30106 &39.85879 &3.44227 \\
Local (Algorithm only) &10 &20000263 & & &44.16319 &40.60699 &3.55620 \\
Heroku (API) &10 &20000263 &MEMORY OVERFLOW & & & & \\
PAW (API) &10 &20000263 &MEMORY OVERFLOW & & & & \\
\multicolumn{1}{c}{AVERAGE} &45.78921 &0.01309 &50.78216 &46.78604 &3.99612 \\
& &STDV &3.4952824449691047 &0.00497738403016791 &8.855024886265406 &8.2442634610736 &0.6482773532436392 \\
\hline
\end{tabular}
\end{adjustbox}
\end{table}
\end{document}
有几行额外的代码是不需要的,但我只是使用了我的旧表,希望它能有所帮助。