检测到超满的 \hbox(宽 3.8889pt)

检测到超满的 \hbox(宽 3.8889pt)

我的代码:大家出了什么问题?

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

答案1

  • 您的表格太宽,无法容纳文本宽度
  • 可以用两种方法来缩小表:

    • 使用以下技巧

      \setlength\tabcolsep{0pt}
      \begin{tabular*}{\linewidth}{@{\extracolsep{\fill}} l *{8}{S} }
      
    • 使用字体大小\small

  • 即使这样,你还是会收到类似以下警告

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

    对于每个表行,括号中是数字。

    这些警告是由于在数字周围使用括号引起的。显然,它们需要在定义列S样式时保留数字的空间。如果您增加到table-format-1.4这些警告就会消失,但表格会变得更宽。您有三个选择:

    • 进一步减小字体大小,例如\scriptsize(不推荐)
    • 使用包changepage并为表格使本地文本宽度更宽(例如\marginparwidth
    • 因为这些警告不会损害生活,所以这些警告只会table-format从你的改变1.3-1.3

考虑上述姆韦(其中我删除了显示表格所需的所有不必要的内容)是:

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

这使:

在此处输入图片描述

(红线表示文本边框)。

附录: 同时,我找到了第四种可能的解决方案,适用于您的特定情况。使用肮脏的技巧,当您规定四位小数时,可以补偿增加的表格宽度,其中第四位是)。技巧是设置负数\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} }

...

与它和\small字体大小的编译姆韦不会再抱怨过满,\hbox并会给出以下结果:

在此处输入图片描述

您可以观察到,两个结果之间的差异可以忽略不计。

答案2

导致框溢出的原因3.8889pt是表格中数字周围的括号。可以通过将它们括在花括号中来避免这种情况,例如{(}{)}并添加table-space-text-pre = (到 siunitx 设置中(无需调整帖子空间,因为 *** 分配了足够的空间)。

以下示例中的代码仍将导致 3 个溢出的框,因为我决定删除加号或减号的空间,table-format = 1.3以使括号完全适合数字。

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

在此处输入图片描述

(源代码基于你之前的问题我的顶部规则和底部规则的宽度不同?因为这个更完整,更易于编译)

相关内容