4

I have the following code. As you can see, in the column definition I have put @{} as suggested here

\documentclass[draft]{scrbook}

\usepackage{dcolumn,booktabs}

\begin{document}

\newcolumntype{P}[1]{D{.}{.}{#1}}

\begin{tabular}{ @{} l *{4}{P{3}} @{} }
  \toprule
  Treatment      & \multicolumn{1}{c}{X} & \multicolumn{1}{c}{Y} & \multicolumn{1}{c}{Diff.}  & \multicolumn{1}{c}{p-value} \\
  \midrule
  MgmtInTreated  & 0.473 & 0.537 &  0.063 &  0.52\% \\
  MgmtOutTreated & 0.505 & 0.443 & -0.062 & 96.67\% \\
  \midrule
  TecInTreated   & 0.482 & 0.535 &  0.053 &  2.45\% \\
  TecOutTreated  & 0.504 & 0.422 &  0.082 & 98.19\% \\
  \midrule
  OthInTreated   & 0.49  & 0.509 &  0.017 & 28.32\% \\
  OthOutTreated  & 0.5   & 0.447 & -0.053 & 87.91\% \\
  \bottomrule
\end{tabular}

\end{document}

The result is this:

enter image description here

The document is in draft mode, so the black boxes are overfull boxes.

And I get the resulting Overfull box warnings in the logs. Why I get this warning when the table clearly don't exceed the \textwidth, and how can I solve them?

Using tabularx with \textwidth does not help either.

7

As the log messages show it is not one overfull box from the table being wider than the text width, it is an overfull box in the last cell of each each row, for example:

Overfull \hbox (3.65001pt too wide) detected at line 18
$\OML/cmm/m/it/10.95 :\OT1/cmr/m/n/10.95 19%$ |

because you specified 3 but the the % is wider than a digit so you have more than the width of three digits after the decimal point.

You get no warnings from

\begin{tabular}{ @{} l *{3}{P{3}}P{4} @{} }
  • thank you Sir! so the percentage take 2 digits, right? – raffamaiden Dec 1 '17 at 20:36
  • may I also ask how did you discover the problem? just looking at the log file? The log file does not tell you that it's the percentage – raffamaiden Dec 1 '17 at 20:41
  • 2
    @raffamaiden well it was already clear from the image you posted, the log file just confirmed it, a table that is too wide would make a single overfull box rule the height of the table, not one in each cell. if your cells are overfull then you have a fixed width box somewhere as a column like l can not be overfull as it grows as needed, so since the column type in that column is D..{3} making it wider is what needs to be done. – David Carlisle Dec 1 '17 at 20:44
  • @raffamaiden the log file does show it is the percentage, the example above shows you that the full content of one of the overfull boxes is .19% in math mode. – David Carlisle Dec 1 '17 at 21:49
7

You can avoid guessing the width of \% by using siunitx. In my opinion it's better not to repeat \% in all entries, so I provide two distinct solutions.

\documentclass[draft]{scrbook}

\usepackage{siunitx,booktabs}

\begin{document}

\begin{tabular}{
  @{}
  l
  S[table-format=1.3]
  S[table-format=1.3]
  S[table-format=-1.3]
  S[table-format=2.2]
  @{}
 }
\toprule
Treatment      & {X} & {Y} & {Diff.}  & {$p$-value (\%)} \\
\midrule
MgmtInTreated  & 0.473 & 0.537 &  0.063 &  0.52 \\
MgmtOutTreated & 0.505 & 0.443 & -0.062 & 96.67 \\
\midrule
TecInTreated   & 0.482 & 0.535 &  0.053 &  2.45 \\
TecOutTreated  & 0.504 & 0.422 &  0.082 & 98.19 \\
\midrule
OthInTreated   & 0.49  & 0.509 &  0.017 & 28.32 \\
OthOutTreated  & 0.5   & 0.447 & -0.053 & 87.91 \\
\bottomrule
\end{tabular}

\bigskip

\begin{tabular}{
  @{}
  l
  S[table-format=1.3]
  S[table-format=1.3]
  S[table-format=-1.3]
  S[table-format=2.2,table-space-text-post=\%]
  @{}
 }
\toprule
Treatment      & {X} & {Y} & {Diff.}  & {$p$-value} \\
\midrule
MgmtInTreated  & 0.473 & 0.537 &  0.063 &  0.52\% \\
MgmtOutTreated & 0.505 & 0.443 & -0.062 & 96.67\% \\
\midrule
TecInTreated   & 0.482 & 0.535 &  0.053 &  2.45\% \\
TecOutTreated  & 0.504 & 0.422 &  0.082 & 98.19\% \\
\midrule
OthInTreated   & 0.49  & 0.509 &  0.017 & 28.32\% \\
OthOutTreated  & 0.5   & 0.447 & -0.053 & 87.91\% \\
\bottomrule
\end{tabular}

\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.