1

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}
6
  • how to fix it guys? thx
    – Johnny
    Commented Jan 4, 2019 at 8:36
  • 5
    Your table is too wide, that's 'wrong' with it ;-)
    – user31729
    Commented Jan 4, 2019 at 8:37
  • You can condense the problem to \documentclass{article} \usepackage{siunitx} \sisetup{ input-symbols = (), table-format = -1.3, table-space-text-post = ***, table-align-text-post = false, group-digits = false } \begin{document} \begin{tabular}{S} (0.098)\\ \end{tabular} \end{document} Your table is not too wide, it is a problem with the setup of the S column but I have no idea how to solve it. Increasing the pre and post space does not help. Commented Jan 4, 2019 at 9:38
  • The problem is that currently the s column allocates enough room for the "pure" number but not for the () around it. Dirty hack and definitly the wrong thing to do: allocate more space by using table-format = -2.4 Commented Jan 4, 2019 at 9:46
  • Change margins of 1in to 1mm and remove \hspace*{-2.2cm}. Then fit perfectly ;-) Suggestion: \footnotesize\centering to left a decent margin. Question: Are you using R for the statistics? if yes, you should try the stargazer package.
    – Fran
    Commented Jan 4, 2019 at 10:06

2 Answers 2

3
  • 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.

1

The source of the 3.8889pt overfull boxes are the parenthesis around the numbers in your table. This can be avoided by wrapping them in curly brackets, e.g. {(} and {)} and adding table-space-text-pre = ( to the siunitx setup (adjusting the post space is not necessary, because the *** allocate more than enough room).

The code in the following example will still result in 3 overfull boxes, because I decided to remove the space for plus or minus signs from table-format = 1.3 in favour of having the parenthesis fit exactly around the numbers.

\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}
\usepackage{rotating} % for 'sidewaystable' env.

\setlength\heavyrulewidth{0.14em}
\setlength\lightrulewidth{0.14em}

\begin{document}
\begin{sidewaystable}
\sisetup{
  input-symbols         = (),
  table-format          = 1.3,
  table-space-text-post = ***,
  table-space-text-pre  = (,
  table-align-text-post = false,
  group-digits          = false
}
\noindent
\begin{tabular}{@{}l *{8}{S} @{}} 
\arrayrulecolor{blue} 
\toprule
          & {(1)} & {(2)} & {(3)} & {(4)} & {(5)} & {(6)} & {(7)} & {(8)} \\
Variables & {FullD} & {FullD} & {FullD} & {FullD} & {FullD} & {FullD} & {FullD} & {FullD} \\ 
\midrule
STI\_30   & 0.301*** & 0.179** & 0.152* & 0.159 & -0.000 & 0.107 & 0.097 & 0.115 \\
          & {(}0.087{)} & {(}0.085{)} & {(}0.085{)} & {(}0.097{)} & {(}0.003{)} & {(}0.084{)} & {(}0.094{)} & {(}0.105{)} \\
Produce\_Full\_SR &  & 0.349*** & 0.321*** & 0.303* & 0.318*** & 0.270*** & 0.244*** & 0.257*** \\
          &  & {(}0.071{)} & {(}0.074{)} & {(}0.170{)} & {(}0.074{)} & {(}0.074{)} & {(}0.078{)} & {(}0.090{)} \\
Has\_Sus\_Efforts &  &  & 0.078*** & 0.077*** & 0.245*** & 0.001 & 0.046** & 0.129*** \\
          &  &  & {(}0.020{)} & {(}0.020{)} & {(}0.094{)} & {(}0.013{)} & {(}0.019{)} & {(}0.041{)} \\
1o.STI\_30\#1o.Produce\_Full\_SR &  &  &  & 0.000 &  &  &  &  \\
          &  &  &  & {(}0.000{)} &  &  &  &  \\
1o.STI\_30\#1o.Has\_Sus\_Efforts &  &  &  &  & 0.000 &  &  &  \\
          &  &  &  &  & {(}0.000{)} &  &  &  \\
Water\_Efforts &  &  &  &  &  & 0.168*** &  &  \\
          &  &  &  &  &  & {(}0.039{)} &  &  \\
C\_or\_S  &  &  &  &  &  &  & 0.202*** &  \\
          &  &  &  &  &  &  & {(}0.066{)} &  \\
C\_or\_S1 &  &  &  &  &  &  &  & 0.221** \\
          &  &  &  &  &  &  &  & {(}0.100{)} \\
Constant  & 0.054*** & 0.029*** & -0.001 & -0.002 & 0.000 & -0.001 & 0.000 & 0.000 \\
          & {(}0.010{)} & {(}0.008{)} & {(}0.003{)} & {(}0.003{)} & {(}0.003{)} & {(}0.003{)} & {(}0.000{)} & {(}0.000{)} \\
\midrule
Observations & {566} & {555} & {552} & {552} & {552} & {552} & {252} & {140} \\
Year FE      & {No} & {No} & {No} & {No} & {No} & {No} & {No} & {No} \\
No.\ of obs  & {566} & {555} & {552} & {552} & {552} & {552} & {252} & {140} \\
Adjusted\ R\textsuperscript{2} & {0.0696} & {0.211} & {0.233} & {0.232} & {0.234} & {0.275} & {0.199} & {0.133} \\ 
\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{document}

enter image description here

(source code is based on your previous question my toprule and bottomrule width are different? because this one was more complete and compilable)

2
  • nice explanation (+1)! i would consider problems with parenthesis as bug, since if you reserved space for them with table-space-text-pre = ( and table-space-text-post = ) when necessary, than warning about overfull of \hbox should not have a reason to appear.
    – Zarko
    Commented Jan 4, 2019 at 17:57
  • @Zarko I was thinking about this since yesterday and was totally confused why the pre and post space did not fix this overfull box. Now I think the problem is that without the {} the () are considered part of the number and the pre and post space does not influence the space for the number itself. Commented Jan 4, 2019 at 18:07

You must log in to answer this question.

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