表格边框缺失

表格边框缺失
\documentclass{article}
\usepackage{siunitx,booktabs}
\newsavebox{\toptabular}
\begin{document}
\begin{table}
\centering

\sbox{\toptabular}{%
  \begin{tabular}{ @{} l r @{\hspace{3em}} l r @{} }
  \toprule
  \multicolumn{4}{@{}l}{\bfseries Probit Regression Results} \\
  \midrule
  Dep.\@ Variable &             Excess return sign   &   No.\@ Observations &       \num{254} \\
  Model           &           Probit   &   Df Residuals       &       \num{248} \\
  Methods         &              MLE   &   Df Model           &         \num{5} \\
  Date            & Thu, 16 Apr 2020   &   Pseudo R-squ.      &    \num{0.1311} \\
  Time            &         00:35:44   &   Log-Likelihood     &   \num{-149.65} \\
  Converge        &             True   &   LL-Null            &   \num{-172.23} \\
  Covariance Type &        nonrobust   &   LLR p-value        & \num{1.341e-08} \\
  \bottomrule
  \end{tabular}%
}
\usebox{\toptabular}

\bigskip

\begin{tabular*}{\wd\toptabular}{
  @{\extracolsep{\fill}}
  l
  S[table-format=-2.4]
  S[table-format=2.3]
  S[table-format=-1.3]
  S[table-format=1.3]
  S[table-format=-2.3,table-align-text-pre=false,table-space-text-pre={[}]
  S[table-format=-1.3,table-space-text-post={]}]% the minus also covers the second digit
  @{}
}
\toprule
       &   {Correlation Coefficient} & {Standard Error} &  {$z$} & {$P>|z|$} &  [0.025 &  0.975] \\
\midrule
const  &  -5.1870 &     1.270 & -4.083 &     0.000 &  -7.677 & -2.697  \\
Recession    &  -0.8608 &     0.394 & -2.183 &     0.029 &  -1.634 & -0.088  \\
Dividend to price &   0.3881 &     0.087 &  4.483 &     0.000 &   0.218 &  0.558  \\
Earning to price     &  11.3808 &     2.526 &  4.505 &     0.000 &   6.429 & 16.332  \\
Term spread    &  -1.3759 &     1.721 & -0.799 &     0.424 &  -4.750 &  1.998  \\
\bottomrule
\end{tabular*}

\end{table}
\end{document}

在此处输入图片描述

上面的代码用于绘图,但是我绘制了另一个表格,结果就是图片中的结果,但是当我使用包xltabular绘制描述表格时发生了这种情况,我该如何解决这个问题。

答案1

第二个表格中的某些表格标题相当长;整体来看,第二个表格太宽,无法容纳第一个表格的宽度。

我建议您 (a) 缩短相当多的标题单元格和 (b)tabular*对两个表都使用环境,将宽度都设置为\textwidth。我还会减少显示的回归系数的位数 (不是我还将第一个表格中的四列内容左对齐。

在此处输入图片描述

\documentclass{article}
\usepackage[tight-spacing]{siunitx}
\usepackage{booktabs}
\begin{document}

\begin{table}
\setlength\tabcolsep{0pt} % let LaTeX determine optimal intercolumn whitespace 
\begin{tabular*}{\textwidth}{ @{\extracolsep{\fill}} 
   ll @{\hspace{3em}} ll }
\toprule
  \multicolumn{4}{l}{\bfseries Probit Regression Results} \\
  \midrule
  Dep.\ Variable  & Excess return sign &   No.\ Observations  &       \num{254} \\
  Model           &           Probit   &   Df Residuals       &       \num{248} \\
  Method          &              MLE   &   Df Model           &         \num{5} \\
  Date            & Thu, 16 Apr 2020   &   Pseudo R$^{2}$     &    \num{0.1311} \\
  Time            &         00:35:44   &   Log-Likelihood     &   \num{-149.65} \\
  Converge        &             True   &   LL-Null            &   \num{-172.23} \\
  Covariance Type &        nonrobust   &   LLR $p$-value      & \num{1.341e-08} \\
\bottomrule
\end{tabular*}

\bigskip
\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}
  l
  S[table-format=-1.3,round-mode=places,round-precision=3]
  S[table-format= 1.3]
  S[table-format=-1.3]
  S[table-format= 1.3]
  S[table-format=-1.3]
  S[table-format=-1.3]
  @{}
}
\toprule
   & {Coeff.} & {Std.\ Error} & {$z$} & {$P>|z|$} & {[0.025} & \multicolumn{1}{r}{0.975]} \\
\midrule
const             &  -5.1870 &     1.270 & -4.083 &     0.000 &  -7.677 & -2.697  \\
Recession         &  -0.8608 &     0.394 & -2.183 &     0.029 &  -1.634 & -0.088  \\
Dividend to price &   0.3881 &     0.087 &  4.483 &     0.000 &   0.218 &  0.558  \\
Earning to price  &  11.3808 &     2.526 &  4.505 &     0.000 &   6.429 & 16.332  \\
Term spread       &  -1.3759 &     1.721 & -0.799 &     0.424 &  -4.750 &  1.998  \\
\bottomrule
\end{tabular*}
\end{table}

\end{document}

答案2

几乎与@Mico 答案 (1) 相同...

在此处输入图片描述

\documentclass{article}
\usepackage{booktabs, makecell}
\usepackage{siunitx}
\newsavebox{\toptabular}


\begin{document}
\begin{table}
\centering

\sbox{\toptabular}{%
  \begin{tabular}{ @{} l r @{\hspace{3em}} l r @{} }
  \toprule
  \multicolumn{4}{@{}l}{\bfseries Probit Regression Results} \\
  \midrule
  Dep.\@ Variable &             Excess return sign   &   No.\@ Observations &       \num{254} \\
  Model           &           Probit   &   Df Residuals       &       \num{248} \\
  Methods         &              MLE   &   Df Model           &         \num{5} \\
  Date            & Thu, 16 Apr 2020   &   Pseudo R-squ.      &    \num{0.1311} \\
  Time            &         00:35:44   &   Log-Likelihood     &   \num{-149.65} \\
  Converge        &             True   &   LL-Null            &   \num{-172.23} \\
  Covariance Type &        nonrobust   &   LLR p-value        & \num{1.341e-08} \\
  \bottomrule
  \end{tabular}%
}
\usebox{\toptabular}

\bigskip
\setlength\tabcolsep{0pt}   % <--- new
\begin{tabular*}{\wd\toptabular}{
  @{\extracolsep{\fill}}
  l
  S[table-format=-2.4]
  S[table-format= 1.3]
  S[table-format=-1.3]
  S[table-format= 1.3]
  S[table-format=-1.3,table-align-text-pre=false,table-space-text-pre={[}]
  S[table-format= 2.3,table-space-text-post={]}]% the minus also covers the second digit
  @{}
}
\toprule
       &   {\makecell{Correlation\\ Coefficient}}   % <--- changed
            &   {\makecell{Standard\\ Error}}       % <--- changed
                &  {$z$} & {$P>|z|$} &  [0.025 &  0.975] \\
\midrule
const  &  -5.1870 &     1.270 & -4.083 &     0.000 &  -7.677 & -2.697  \\
Recession    &  -0.8608 &     0.394 & -2.183 &     0.029 &  -1.634 & -0.088  \\
Dividend to price &   0.3881 &     0.087 &  4.483 &     0.000 &   0.218 &  0.558  \\
Earning to price     &  11.3808 &     2.526 &  4.505 &     0.000 &   6.429 & 16.332  \\
Term spread    &  -1.3759 &     1.721 & -0.799 &     0.424 &  -4.750 &  1.998  \\
\bottomrule
\end{tabular*}

\end{table}
\end{document}

与您的 MWE 相比,我在第二个表格前面添加了一个\setlength\tabcolsep{0pt},并使用makecell同名包中的命令将第二列和第三列的列标题写在两行中。这样,第二个表格的宽度就缩小到了 的宽度\toptabular

相关内容