[Tex/LaTex] Overfull \hbox (3.8889pt too wide) detected

siunitxtables

my code: what's wrong guys?

\documentclass{article}
\usepackage[letterpaper,margin=1in]{geometry}
\setlength{\pdfpagewidth}{8.5in} 
\setlength{\pdfpageheight}{11in}
\usepackage[english]{babel}
\usepackage{colortbl} 
\usepackage{array}


\usepackage{amssymb,amsmath,array}
\usepackage{siunitx} % don't use 'detect-all' switch unless you know what you're doing
\usepackage{booktabs, etoolbox}
\usepackage{rotating} % for 'sidewaystable' env.

\newlength{\toprulewidth}
\setlength{\toprulewidth}{0.14em}
\patchcmd{\toprule}% <cmd>
{\heavyrulewidth}{\toprulewidth}% <search><replace>
{}{}% <success><failure>
\patchcmd{\bottomrule}% <cmd>
{\heavyrulewidth}{\toprulewidth}% <search><replace>
{}{}% <success><failure>


\newlength{\midrulewidth}
\setlength{\midrulewidth}{0.1em}
\patchcmd{\midrule}% <cmd>
{\lightrulewidth}{\midrulewidth}% <search><replace>
{}{}% <success><failure>


%\setlength\heavyrulewidth{0.14em}
%\setlength\lightrulewidth{0.1em}
%\setlength{\cmidrulewidth}{0.06em}

\begin{document}
    %\begin{figure}
    %\begin{adjustwidth}{-3cm}{}

    %\begin{sidewaystable}
    \sisetup{
        input-symbols         = (),
        table-format          = -1.3,
        table-space-text-post = ***,
        table-align-text-post = false,
        group-digits          = false
    }
    \noindent
    \hspace*{-2.2cm}\begin{tabular}{@{}l *{8}{S} @{}} 
        \arrayrulecolor{blue} 
        \toprule
        & {(1)} & {(2)} & {(3)} & {(4)} & {(5)} & {(6)} & {(7)} & {(8)} \\
        Variables & {EmiD} & {EmiD} & {EmiD} & {EmiD} & {EmiD} & {EmiD} & {EmiD} & {EmiD} \\ 
        \midrule
STI\_30 & 0.359*** & 0.237** & 0.226** & 0.220* & 0.220* & 0.144 & 0.096 & 0.103 \\
 & (0.098) & (0.094) & (0.095) & (0.125) & (0.125) & (0.120) & (0.117) & (0.152) \\
Produce\_Full\_SR &  & 0.411*** & 0.423*** & 0.436** & 0.436** & 0.390** & 0.350** & 0.313* \\
 &  & (0.077) & (0.078) & (0.170) & (0.170) & (0.167) & (0.166) & (0.175) \\
Has\_Sus\_Efforts &  &  & 0.099 & 0.099 & 0.099 & -0.024 &  &  \\
 &  &  & (0.070) & (0.070) & (0.070) & (0.069) &  &  \\
1o.STI\_30\#1o.Produce\_Full\_SR &  &  &  & 0.000 & 0.000 & 0.000 & 0.000 & 0.000 \\
 &  &  &  & (0.000) & (0.000) & (0.000) & (0.000) & (0.000) \\
1o.STI\_30\#1o.Has\_Sus\_Efforts &  &  &  &  & 0.000 & 0.000 & 0.000 & 0.000 \\
 &  &  &  &  & (0.000) & (0.000) & (0.000) & (0.000) \\
Water\_Efforts &  &  &  &  &  & 0.230*** & 0.202*** &  \\
 &  &  &  &  &  & (0.046) & (0.047) &  \\
C\_or\_S &  &  &  &  &  &  & 0.145** & 0.156* \\
 &  &  &  &  &  &  & (0.072) & (0.092) \\
C\_or\_S1 &  &  &  &  &  &  &  & 0.209** \\
 &  &  &  &  &  &  &  & (0.097) \\
Constant & 0.176*** & 0.108*** & 0.014 & 0.015 & 0.015 & 0.029 & -0.002 & 0.158*** \\
 & (0.026) & (0.023) & (0.064) & (0.064) & (0.064) & (0.066) & (0.018) & (0.050) \\
\midrule

Observations & {249} & {249} &{ 248} & {248} & {248} &{ 248} & {237} & {135} \\
Year FE & {No} & {No} & {No} &{ No} &{ No} & {No} & {No} & {No} \\
 Adjusted R-squared &{ 0.0721} & {0.220} &{ 0.225} &{ 0.222} & {0.222} & {0.284} & {0.295} & {0.200} \\ 
\bottomrule
\addlinespace
\multicolumn{9}{c}{Robust standard errors in parentheses} \\
\multicolumn{9}{c}{$^{***}\ p<0.01$; $^{**}\ p<0.05$; $^{*}\ p<0.1$} \\
\end{tabular}
%\end{sidewaystable}
%\end{adjustwidth}
%\end{figure}

Best Answer

  • your table is to wide that can be fit in text width
  • table can be shrink with two measures:

    • using the following trick

      \setlength\tabcolsep{0pt}
      \begin{tabular*}{\linewidth}{@{\extracolsep{\fill}} l *{8}{S} }
      
    • using font size \small

  • even with this you will get warnings like

    Overfull \hbox (3.5972pt too wide) detected at line 63
    

    for each table row, where are numbers in parenthesis.

    these warnings are caused by use of parenthesis around of numbers. apparently they require reservation of digit's space in the definition for S column style. if you would increase table-format to -1.4 than these warnings will disappear, but table will become even wider. than you have three choices:

    • further reduce font size, for example to \scriptsize (not recommended)
    • use the package changepage and for table make locally text width wider (for example for \marginparwidth)
    • since this warnings doesn't harm live with these warning and change the table-format only from yours 1.3 to -1.3.

consider aforementioned the mwe (in which i remove all what is not necessary for show your table) is:

\documentclass{article}
\usepackage[letterpaper,margin=1in]{geometry}
\usepackage[table]{xcolor}

\usepackage{siunitx} % don't use 'detect-all' switch unless you know what you're doing
\usepackage{array, booktabs}

%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%

\begin{document}
    \begin{figure}
    \small
\sisetup{
    input-symbols         = (),
    table-format          = -1.3,
    table-space-text-pre = (,
    table-space-text-post = ***,
    table-align-text-post = false,
    group-digits          = false
    }
    \arrayrulecolor{blue}
    \setlength\tabcolsep{0pt}
    \begin{tabular*}{\linewidth}{@{\extracolsep{\fill}} l *{8}{S} }
    \toprule
            & {(1)}  & {(2)}  & {(3)}  & {(4)}  & {(5)}  & {(6)}  & {(7)}  & {(8)}  \\
Variables   & {EmiD} & {EmiD} & {EmiD} & {EmiD} & {EmiD} & {EmiD} & {EmiD} & {EmiD} \\
    \midrule
STI\_30 & 0.359*** & 0.237** & 0.226** & 0.220*  & 0.220*  & 0.144   & 0.096   & 0.103   \\
        & (0.098)  & (0.094) & (0.095) & (0.125) & (0.125) & (0.120) & (0.117) & (0.152) \\
    \addlinespace
Produce\_Full\_SR
        &  & 0.411*** & 0.423*** & 0.436** & 0.436** & 0.390** & 0.350** & 0.313* \\
        &  & (0.077) & (0.078) & (0.170) & (0.170) & (0.167) & (0.166) & (0.175) \\
    \addlinespace
Has\_Sus\_Efforts
        &  &  & 0.099 & 0.099 & 0.099 & -0.024 &  &  \\
        &  &  & (0.070) & (0.070) & (0.070) & (0.069) &  &  \\
    \addlinespace
1o.STI\_30\#1o.Produce\_Full\_SR
        &  &  &  & 0.000 & 0.000 & 0.000 & 0.000 & 0.000 \\
        &  &  &  & (0.000) & (0.000) & (0.000) & (0.000) & (0.000) \\
    \addlinespace
1o.STI\_30\#1o.Has\_Sus\_Efforts
        &  &  &  &  & 0.000 & 0.000 & 0.000 & 0.000 \\
        &  &  &  &  & (0.000) & (0.000) & (0.000) & (0.000) \\
    \addlinespace
Water\_Efforts
        &  &  &  &  &  & 0.230*** & 0.202*** &  \\
        &  &  &  &  &  & (0.046) & (0.047) &  \\
    \addlinespace
C\_or\_S
        &  &  &  &  &  &  & 0.145** & 0.156* \\
        &  &  &  &  &  &  & (0.072) & (0.092) \\
    \addlinespace
C\_or\_S1
        &  &  &  &  &  &  &  & 0.209** \\
        &  &  &  &  &  &  &  & (0.097) \\
    \addlinespace
Constant
        & 0.176*** & 0.108*** & 0.014 & 0.015 & 0.015 & 0.029 & -0.002 & 0.158*** \\
        & (0.026)  & (0.023) & (0.064) & (0.064) & (0.064) & (0.066) & (0.018) & (0.050) \\
    \midrule
Observations
        & {249} & {249} &{ 248} & {248} & {248} &{ 248} & {237} & {135} \\
Year FE & {No} & {No} & {No} &{ No} &{ No} & {No} & {No} & {No} \\
 Adjusted R-squared
        & {0.0721} & {0.220} &{ 0.225} &{ 0.222} & {0.222} & {0.284} & {0.295} & {0.200} \\
    \midrule[\heavyrulewidth]
\multicolumn{9}{l}{Robust standard errors in parentheses} \\
\multicolumn{9}{l}{$^{***}\ p<0.01$; $^{**}\ p<0.05$; $^{*}\ p<0.1$} \\
\end{tabular*}
    \end{figure}
\end{document}

which gives:

enter image description here

(red lines indicates text borders).

addendum: meanwhile i found the fourth possible solution for your particular case. With dirty trick is possible to compensate increased table's width when you prescribe four decimal digits, where the forth is for ). The trick is to set negative \tablcolsep:

...
    \begin{figure}
    \small
\sisetup{
    input-symbols         = (),
    table-format          = -1.4,  % <---
    table-space-text-post = ***,
    table-align-text-post = false,
    group-digits          = false
    }
    \arrayrulecolor{blue}
    \setlength\tabcolsep{-3pt} % <---
    \begin{tabular*}{\linewidth}{@{\extracolsep{\fill}} l *{8}{S} }

...

with it with and \small font size the compilation of mwe will not complain about overfull \hbox anymore and will give the following result:

enter image description here

you can observe, that differences between both results are negligible.