7

Consider the following example:

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

output

I get the following warning:

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

for lines 27--36.

How do I get rit of these without changing the output layout in the table?

4
  • What's the use of \spc?
    – egreg
    Commented Aug 26, 2013 at 19:59
  • You are not reserving any space for your spaces! What are they for anyway?
    – Joseph Wright
    Commented Aug 26, 2013 at 20:01
  • @egreg To move the second and third column of data to the right (to center them relative to "Eleverne fra 9. A"), and the forth and fifth column of data to center them relative to "Eleverne fra 9. B". Commented Aug 26, 2013 at 20:05
  • @JosephWright See comment to egreg. Commented Aug 26, 2013 at 20:05

1 Answer 1

6

It's better to increase the size of the items in the second header row:

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

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .