我使用siunitx
包创建了此表,因为值必须以科学计数法表示。不幸的是,表格超出了边距。我该如何解决这个问题?
\documentclass[12pt,a4paper,oneside,openright]{book}
\usepackage[hmargin=3cm,vmargin=3cm,bindingoffset=0.5cm]{geometry}
\usepackage{siunitx}
\begin{document}
\begin{table}[htp]
\centering
\rowcolors{1}{}{lightgray}
\sisetup{table-format=1.4e06,exponent-product = \cdot}
\begin{tabular}{lSSSSS}
\toprule
{\emph{Nodi}} & \multicolumn{5}{c}{Sistemi di trasmissione} \\
\cmidrule{2-6} & {BC} & {$\text{PNC}_{16}$} & {$\text{PNC}_{32}$} & {{$\text{PNC}_{64}$}} & {$\text{PNC}_{128}$} \\ \midrule
1 & 1.4307e-06 & 2.4116e-05 & 4.6601e-05 & 9.145e-05 & 1.9019e-04 \\
3 & 2,108e-06 & 2.5738e-05 & 5.1332e-05 & 9.775e-05 & 1.9374e-04 \\
7 & 2.7708e-06 & 2.7964e-05 & 5.324e-05 & 1.0158e-04 & 2.0066e-04 \\
12 & 3.2206e-06 & 2.905e-05 & 5.5356e-05 & 1.0441e-04 & 2.0528e-04 \\
20 & 3.6241e-06 & 2.9865e-05 & 5.6242e-05 & 1.0698e-04 & 2.0324e-04 \\
25 & 3.8909e-06 & 3.0289e-05 & 5.614e-05 & 1.0648e-04 & 2.0663e-04 \\
35 & 4.2468e-06 & 3.1154e-05 & 5.7399e-05 & 1.0791e-04 & 2.0598e-04 \\
50 & 4.4803e-06 & 3.1883e-05 & 5.8366e-05 & 1.0964e-04 & 2.0811e-04 \\
65 & 4.7681e-06 & 3.2091e-05 & 5.8808e-05 & 1.1044e-04 & 2.0992e-04 \\
75 & 4.9844e-06 & 3.2443e-05 & 5.9032e-05 & 1.099e-04 & 2.1003e-04 \\
90 & 5.1003e-06 & 3.2914e-05 & 5.9188e-05 & 1.1086e-04 & 2.0996e-04 \\
100 & 5.2175e-06 & 3.3087e-05 & 5.9855e-05 & 1.1089e-04 & 2.1143e-04 \\ \bottomrule
\end{tabular}
\end{table}
\end{document}
答案1
表格适合边距,无需设置,也无需使用以下代码\small
减少太多。注意\tabcolsep
table-format=1.4e-1
键,它精确地说明了您需要的空间。这意味着:
- 整数部分为一位数字
- 四位小数
- 指数部分的符号
- 指数为一位数字
table-format=1.4e06
为指数保留的六位数字。
\documentclass[12pt,a4paper,oneside,openright]{book}
\usepackage[hmargin=3cm,vmargin=3cm,bindingoffset=0.5cm]{geometry}
\usepackage{siunitx,booktabs}
\usepackage[table]{xcolor}
\begin{document}
\begin{table}[htp]
\centering
\rowcolors{1}{}{lightgray}
\sisetup{table-format=1.4e-1,exponent-product = \cdot}
\addtolength{\tabcolsep}{-.5pt}
\begin{tabular}{rSSSSS}
\toprule
\multicolumn{1}{c}{\emph{Nodi}} &
\multicolumn{5}{c}{Sistemi di trasmissione} \\
\cmidrule{2-6}
& {BC} &
{$\text{PNC}_{16}$} &
{$\text{PNC}_{32}$} &
{$\text{PNC}_{64}$} &
{$\text{PNC}_{128}$} \\
\midrule
1 & 1.4307e-06 & 2.4116e-05 & 4.6601e-05 & 9.145e-05 & 1.9019e-04 \\
3 & 2,108e-06 & 2.5738e-05 & 5.1332e-05 & 9.775e-05 & 1.9374e-04 \\
7 & 2.7708e-06 & 2.7964e-05 & 5.324e-05 & 1.0158e-04 & 2.0066e-04 \\
12 & 3.2206e-06 & 2.905e-05 & 5.5356e-05 & 1.0441e-04 & 2.0528e-04 \\
20 & 3.6241e-06 & 2.9865e-05 & 5.6242e-05 & 1.0698e-04 & 2.0324e-04 \\
25 & 3.8909e-06 & 3.0289e-05 & 5.614e-05 & 1.0648e-04 & 2.0663e-04 \\
35 & 4.2468e-06 & 3.1154e-05 & 5.7399e-05 & 1.0791e-04 & 2.0598e-04 \\
50 & 4.4803e-06 & 3.1883e-05 & 5.8366e-05 & 1.0964e-04 & 2.0811e-04 \\
65 & 4.7681e-06 & 3.2091e-05 & 5.8808e-05 & 1.1044e-04 & 2.0992e-04 \\
75 & 4.9844e-06 & 3.2443e-05 & 5.9032e-05 & 1.099e-04 & 2.1003e-04 \\
90 & 5.1003e-06 & 3.2914e-05 & 5.9188e-05 & 1.1086e-04 & 2.0996e-04 \\
100 & 5.2175e-06 & 3.3087e-05 & 5.9855e-05 & 1.1089e-04 & 2.1143e-04 \\
\bottomrule
\end{tabular}
\end{table}
\end{document}
说实话,表格宽度为 413.00468pt,而 为\textwidth
412.56499pt,因此差异为 .44pt,小于\hfuzz
0.5pt(0.18mm)的值。
答案2
\documentclass{article}
\usepackage{siunitx}
\usepackage[table]{xcolor}
\usepackage{algpseudocode,booktabs}
\begin{document}
\begin{table}[htp]
\centering
\small
\setlength\tabcolsep{0pt}
\rowcolors{1}{}{lightgray}
\sisetup{table-format=1.4e06,exponent-product = \cdot}
\begin{tabular}{@{\kern-1pt}lSSSSS@{\kern-1pt}}
\toprule
{\emph{Nodi}} & \multicolumn{5}{c}{Sistemi di trasmissione} \\
\cmidrule{2-6} & {BC} & {$\text{PNC}_{16}$} & {$\text{PNC}_{32}$} & {{$\text{PNC}_{64}$}} & {$\text{PNC}_{128}$} \\ \midrule
1 & 1.4307e-06 & 2.4116e-05 & 4.6601e-05 & 9.145e-05 & 1.9019e-04 \\
3 & 2,108e-06 & 2.5738e-05 & 5.1332e-05 & 9.775e-05 & 1.9374e-04 \\
7 & 2.7708e-06 & 2.7964e-05 & 5.324e-05 & 1.0158e-04 & 2.0066e-04 \\
12 & 3.2206e-06 & 2.905e-05 & 5.5356e-05 & 1.0441e-04 & 2.0528e-04 \\
20 & 3.6241e-06 & 2.9865e-05 & 5.6242e-05 & 1.0698e-04 & 2.0324e-04 \\
25 & 3.8909e-06 & 3.0289e-05 & 5.614e-05 & 1.0648e-04 & 2.0663e-04 \\
35 & 4.2468e-06 & 3.1154e-05 & 5.7399e-05 & 1.0791e-04 & 2.0598e-04 \\
50 & 4.4803e-06 & 3.1883e-05 & 5.8366e-05 & 1.0964e-04 & 2.0811e-04 \\
65 & 4.7681e-06 & 3.2091e-05 & 5.8808e-05 & 1.1044e-04 & 2.0992e-04 \\
75 & 4.9844e-06 & 3.2443e-05 & 5.9032e-05 & 1.099e-04 & 2.1003e-04 \\
90 & 5.1003e-06 & 3.2914e-05 & 5.9188e-05 & 1.1086e-04 & 2.0996e-04 \\
100 & 5.2175e-06 & 3.3087e-05 & 5.9855e-05 & 1.1089e-04 & 2.1143e-04 \\ \bottomrule
\end{tabular}
\end{table}
\noindent X\dotfill X
\end{document}
答案3
多年后......我的回答似乎很有用如何制作一个结合 x 和 s 的列说明符,这个问题后来才被问到。下面是它对这个问题的采纳。
tabularx
表格环境与X
(用于命令中的列标题\multicolumn{1}{... X}{...}
)和列的组合S
使得表格宽度等于文本宽度,并根据S
列类型对齐数字:
(红线显示页面布局的边框)。
\documentclass[12pt,a4paper,oneside,openright]{book}
\usepackage[hmargin=3cm,vmargin=3cm,bindingoffset=0.5cm]{geometry}
\usepackage{caption}
\usepackage[table]{xcolor}
\usepackage{booktabs, multirow, tabularx}
\belowrulesep=0pt
\aboverulesep=0pt
\newcommand\mcx[1]{\multicolumn{1}{>{\centering\arraybackslash}X}{#1}}
\usepackage{siunitx}
\usepackage{showframe}% in real document had to be removed
\renewcommand*\ShowFrameColor{\color{red}}
\begin{document}
\begin{table}%[htp]
\centering
\renewcommand\arraystretch{1.1}
\rowcolors{1}{}{lightgray}
\begin{tabularx}{\linewidth}{S[table-format=3.0]
*{5}{S[table-number-alignment = center,
exponent-product = \cdot,
table-figures-integer = 1,
table-figures-decimal = 4,
table-figures-exponent = 1]}
}
\toprule
{\multirow{2}{*}{\emph{Nodi}}}
& \multicolumn{5}{c}{Sistemi di trasmissione} \\
\cmidrule{2-6}
& \mcx{BC} & \mcx{PNC$_{16}$} & \mcx{PNC$_{32}$} & \mcx{PNC$_{64}$} & \mcx{PNC$_{128}$} \\ \midrule
1 & 1.4307e-06 & 2.4116e-05 & 4.6601e-05 & 9.145e-05 & 1.9019e-04 \\
3 & 2,108e-06 & 2.5738e-05 & 5.1332e-05 & 9.775e-05 & 1.9374e-04 \\
7 & 2.7708e-06 & 2.7964e-05 & 5.324e-05 & 1.0158e-04 & 2.0066e-04 \\
12 & 3.2206e-06 & 2.905e-05 & 5.5356e-05 & 1.0441e-04 & 2.0528e-04 \\
20 & 3.6241e-06 & 2.9865e-05 & 5.6242e-05 & 1.0698e-04 & 2.0324e-04 \\
25 & 3.8909e-06 & 3.0289e-05 & 5.614e-05 & 1.0648e-04 & 2.0663e-04 \\
35 & 4.2468e-06 & 3.1154e-05 & 5.7399e-05 & 1.0791e-04 & 2.0598e-04 \\
50 & 4.4803e-06 & 3.1883e-05 & 5.8366e-05 & 1.0964e-04 & 2.0811e-04 \\
65 & 4.7681e-06 & 3.2091e-05 & 5.8808e-05 & 1.1044e-04 & 2.0992e-04 \\
75 & 4.9844e-06 & 3.2443e-05 & 5.9032e-05 & 1.099e-04 & 2.1003e-04 \\
90 & 5.1003e-06 & 3.2914e-05 & 5.9188e-05 & 1.1086e-04 & 2.0996e-04 \\
100 & 5.2175e-06 & 3.3087e-05 & 5.9855e-05 & 1.1089e-04 & 2.1143e-04 \\
\bottomrule
\end{tabularx}
\end{table}
\end{document}