警告:表格中的 \hbox 过满

警告:表格中的 \hbox 过满

请考虑以下示例:

\documentclass{article}

\usepackage{booktabs,dcolumn}
\usepackage{siunitx}

\newcommand*\mc[1]{\multicolumn{2}{c}{Eleverne fra $9$.~#1}}

\begin{document}

\begin{table}
\def\spc{\hspace{0.8em}}
\centering
 \caption{Something.}
 \label{tbl:1}
  \begin{tabular}{
           S[table-format = 2.1]
    >{\spc}S[table-format = 2]
           S[table-format = 3]
    >{\spc}S[table-format = 2]
           S[table-format = 3]
  }
   \toprule
    {S{\o}vnm{\ae}ngde} & \mc{A} & \mc{B}          \\
   \midrule
    \si{\hour} & {Abs.} & {Rel.} & {Abs.} & {Rel.} \\
   \midrule
     6.5       &  1\spc &   4    &  0\spc &   0    \\
     7         &  4\spc &  16    &  2\spc &  10    \\
     7.5       &  3\spc &  12    &  3\spc &  15    \\
     8         &  8\spc &  32    &  9\spc &  45    \\
     8.5       &  5\spc &  20    &  3\spc &  15    \\
     9         &  2\spc &   8    &  3\spc &  15    \\
     9.5       &  1\spc &   4    &  0\spc &   0    \\
    10         &  1\spc &   4    &  0\spc &   0    \\
   \midrule
               & 25\spc & 100    & 20\spc & 100    \\
   \bottomrule
  \end{tabular}
\end{table}

\end{document}

输出

我收到以下警告:

Overfull \hbox (8.00003pt too wide) detected at line

针对第 27 至 36 行。

如何在不改变表中的输出布局的情况下摆脱这些?

答案1

最好增加第二个标题行中的项目的大小:

\documentclass{article}
\usepackage[utf8]{inputenc}

\usepackage{booktabs,dcolumn}
\usepackage{siunitx}

\newcommand*\mc[1]{\multicolumn{2}{c}{Eleverne fra $9$.~#1}}

\begin{document}

\begin{table}
\centering
\caption{Something.}
\label{tbl:1}
\begin{tabular}{
  S[table-format = 2.1]
  S[table-format = 2]
  S[table-format = 3]
  S[table-format = 2]
  S[table-format = 3]
}
\toprule
{Søvnmængde} & \mc{A} & \mc{B}          \\
\midrule
\si{\hour} & {\quad Abs.\quad} & {\quad Rel.\quad} & {\quad Abs.\quad} & {\quad Rel.\quad} \\
\midrule
 6.5 &  1 &   4 &  0 &   0 \\
 7   &  4 &  16 &  2 &  10 \\
 7.5 &  3 &  12 &  3 &  15 \\
 8   &  8 &  32 &  9 &  45 \\
 8.5 &  5 &  20 &  3 &  15 \\
 9   &  2 &   8 &  3 &  15 \\
 9.5 &  1 &   4 &  0 &   0 \\
10   &  1 &   4 &  0 &   0 \\
\midrule
     & 25 & 100 & 20 & 100 \\
\bottomrule
\end{tabular}
\end{table}

\end{document}

在此处输入图片描述

相关内容