如何才能使各列的宽度相等?

如何才能使各列的宽度相等?

我试图使面板 B 中“预测变量”下的两列宽度相等。

在此处输入图片描述

我查看了其他在线问题。我尝试使用,tabularx但没有用。

有人可以帮帮我吗?

以下是我的代码。

\documentclass[12pt]{article}  %It can be article / report / and book 
\usepackage{amssymb} %One of the math packages
\usepackage[top=1.3in, bottom=1.3in, left=1in, right=1in]{geometry}
\usepackage{setspace}
\usepackage{tabu}
\usepackage{pgflibrarysnakes}
\usepackage{graphics,graphicx,pgfplots,rotating,multirow}
\usepackage{xcolor}
\usepackage{amssymb,amsfonts,amsmath}
\usepackage{color,colortbl}
\usetikzlibrary{snakes}
%\usepackage{ltablex}
\usepackage{caption}
\usepackage{subcaption}
% Footnote space
\usepackage{lipsum}% dummy text

\begin{table}
\caption{Predicting Ex Post Covariances between between Stock Returns and Consumption Growth} \label{Tab6}
\vspace{0.3in}
\begin{spacing}{0.8}
{\footnotesize Table 6 reports }
\end{spacing}
\vspace{0.3in}
\begin{center}
\resizebox{5.5in}{!}{
\begin{tabu}{l|c|c|cc}


    \multicolumn{5}{l}{\textbf{Panel A: 1st stage regression}} \\ \cline{1-5}

   \T  Dependent variable & \multicolumn{2}{|l|}{Predictors} & $F$-statistic & $P$-Value \\ \cline{1-5}

      $r^e_t$ & \multicolumn{2}{|l|}{$D/P_{t-1}$, $SVAR_{t-1}$, $BM_{t-1}$, $NTIS_{t-1}$, $LTY_{t-1}$}  & 4.45 & 0.001  \\ 
             $\Delta c_{CE,t}$ & \multicolumn{2}{|l|}{$\Delta c_{CE,t-1}$, $\Delta c_{CE,t-2}$, $\Delta c_{CE,t-3}$, $r_{f,t-1}$}    & 43.67 & 0.000  \\ 
                          $\Delta c_{NIPA,t}$ & \multicolumn{2}{|l|}{$\Delta c_{NIPA,t-1}$, $\Delta c_{NIPA,t-2}$, $\Delta c_{NIPA,t-3}$, $r_{f,t-1}$}  & 65.14 & 0.000  \\ 
                                                    $\Delta c_{H,t}$ & \multicolumn{2}{|l|}{$\Delta c_{H,t-1}$, $\Delta c_{H,t-2}$, $\Delta c_{H,t-3}$, $r_{f,t-1}$}  & 19.11 & 0.000  \\ \hline \\ \\

    \multicolumn{5}{l}{\textbf{Panel B: 2nd stage regression}} \\ \cline{1-5}
    \T &  \multicolumn{2}{|c|}{Predictors} & & \\ \cline{2-3}  
      Dependent variable & $\hat \epsilon_{r^e,t-1} \hat \epsilon_{\Delta c_{i},t-1}$  & $M/C_{i,t-1}$ & $F$-statistic & $P$-Value \\ \cline{1-5}   
   \T  $\hat \epsilon_{r^e,t} \hat \epsilon_{\Delta c_{CE},t}$ & -0.143** & $1.06\times10^{-5}$ & 2.93 & 0.055  \\
                          \rowfont{\small}    & (-2.26) & (0.85) &  &  \\ 
      \T  $\hat \epsilon_{r^e,t} \hat \epsilon_{\Delta c_{NIPA},t}$ & 0.108  & $-9.27\times10^{-6}$  & 1.34 & 0.264 \\
           \rowfont{\small}    & (1.64) & (-0.23) &  &  \\ 
            \T  $\hat \epsilon_{r^e,t} \hat \epsilon_{\Delta c_{H},t}$ & -0.133** & $-2.65\times10^{-5}$ & 2.28 & 0.105 \\
                       \rowfont{\small}    & (-2.12) & (-0.51) &  &  \\  \hline




    \end{tabu}%
    }
\end{center}
\end{table}
\clearpage

答案1

  1. 我添加了一些快捷方式,因此代码更容易阅读。

    • \mc为了\multicolumn
    • \dc为了\multicolumn{2}{l|}{#1}
  2. 取而代之\usepackage{tabu}\usepackage{tabularx}

输出

在此处输入图片描述

代码(修复了我的错误信息)

\documentclass[12pt]{article}  %It can be article / report / and book 
\usepackage{amssymb,amsfonts,amsmath} % math packages
\usepackage[top=1.3in, bottom=1.3in, left=1in, right=1in]{geometry}
\usepackage{setspace}
\usepackage{booktabs}
\usepackage{tabularx}
\usepackage{array}
\usepackage{graphics,graphicx,rotating,multirow}
\usepackage{xcolor}
\usepackage{color,colortbl}
%\usepackage{ltablex}
\usepackage{caption}
\usepackage{subcaption}
\begin{document}
\thispagestyle{empty}

\def\T{\texttt{T}}
\let\mc=\multicolumn
\newcommand\dc[1]{\mc{2}{l|}{#1}}
\newcommand\heps{\hat\epsilon}
\newlength\myLength
\setlength\myLength{3.7cm}


\begin{tabularx}{\linewidth}{p{2.7cm}|>{\centering}p{\myLength}|>{\centering}p{\myLength}|>{\centering}Xc}

\mc{5}{l}{\textbf{Panel A: 1st stage regression}}             
                      \\ \cline{1-5}
\T-Dependent variable  & \mc{2}{c|}{Predictors}                                                          & $F$-statistic & $P$-Value \\
  \cline{1-5}

$r^e_t$                & \dc{$D/P_{t-1}, SVAR_{t-1}, BM_{t-1}, NTIS_{t-1}, LTY_{t-1}$}                   & 4.45          & 0.001     \\
$\Delta c_{CE,t}$      & \dc{$\Delta c_{CE,t-1}, \Delta c_{CE,t-2}, \Delta c_{CE,t-3}, r_{f,t-1}$}       & 43.67         & 0.000     \\
$\Delta c_{NIPA,t}$    & \dc{$\Delta c_{NIPA,t-1}, \Delta c_{NIPA,t-2}, \Delta c_{NIPA,t-3}, r_{f,t-1}$} & 65.14         & 0.000     \\
$\Delta c_{H,t}$       & \dc{$\Delta c_{H,t-1}, \Delta c_{H,t-2}, \Delta c_{H,t-3}, r_{f,t-1}$}          & 19.11         & 0.000     \\
  \hline

\mc{5}{l}{\rule{0pt}{1cm}\textbf{Panel B: 2nd stage regression}} 
\\ \cline{1-5}
                                              & \mc{2}{c|}{Predictors}                     &                      &               \\
  \cline{2-3}
\T-Dependent variable                         & $\heps_{r^e,t-1} \heps_{\Delta c_{i},t-1}$ & $M/C_{i,t-1}$        & $F$-statistic  & $P$-Value \\
  \cline{1-5}
\T  $\heps_{r^e,t} \heps_{\Delta c_{CE},t}$   & -0.143**                                   & $1.06\times10^{-5}$  & 2.93           & 0.055     \\
                                              & (-2.26)                                    & (0.85)               &                &           \\
\T  $\heps_{r^e,t} \heps_{\Delta c_{NIPA},t}$ & 0.108                                      & $-9.27\times10^{-6}$ & 1.34           & 0.264     \\
                                              & (1.64)                                     & (-0.23)              &                &           \\
\T  $\heps_{r^e,t} \heps_{\Delta c_{H},t}$    & -0.133**                                   & $-2.65\times10^{-5}$ & 2.28           & 0.105     \\
                                              & (-2.12)                                    & (-0.51)              &                &           \\
  \hline

\end{tabularx}%

\end{document}

答案2

在此处输入图片描述

  • 首先我清理前言:不是\usepackage{graphics, graphicx, ...}足够了 \usepackage{graphicx, ...},而是\usepackage{xcolor, color, colortbl}足够了\usepackage[table]{xcolor}amsmath被加载了两次
  • 使用tabu很脆弱;软件包有缺陷,而且不幸的是不再维护
  • 为了更好地对齐最后两列中的数字,使用S包中的列类型很方便siunitx;用它写数字乘以也更简单10^{...}(参见下面的 MWE)
  • 而不是(例如)$\hat \epsilon_{r^e,t-1} \hat \epsilon_{\Delta c_{i},t-1}$是正确的$\hat{\epsilon}_{r^e,t-1} \hat{\epsilon}_{\Delta c_{i},t-1}$
  • 我不清楚SVAR,,NIPA... 是一个变量还是四个变量的集合;我假设前者并将它们写为\mathit{SVAR}
  • tabularx对于等宽列,您需要规定它们的宽度。您可以按照建议使用马苏皮兰在他的回答中,我将

\begin{tabularx}{\linewidth}{p{2.7cm}|
                >{\centering}p{\myLength}|
                >{\centering}p{\myLength}|
                >{\centering}Xc}`

\begin{tabularx}{\linewidth}{l}|
           *{2}{>{\centering}X|}
           *{2}{S[table-format=2.3]}}

用于下面的 MWE(tabularx当然也在序言中添加包)或使用p{...}列类型,如下面的 MWE 中所示:

\documentclass[12pt]{article}  %It can be article / report / and book
\usepackage[top=1.3in, bottom=1.3in, left=1in, right=1in]{geometry}
%\usepackage{setspace}
\usepackage{array, multirow, rotating}
\usepackage{graphicx}
\usepackage{amsmath, amssymb, amsfonts}
\usepackage[table]{xcolor}
\usepackage{graphicx}
\usepackage{pgfplots}
\usetikzlibrary{snakes}
\usepackage{caption}
\usepackage{subcaption}

\usepackage{siunitx}% added

\def\T{\texttt{T}}
\newcommand\mc[1]{ \multicolumn{1}{l}{#1}}
\newcommand\mcc[1]{\multicolumn{2}{>{\raggedright}p{82mm}|}{#1}}

\usepackage{lipsum}% dummy text

\begin{document}
    \begin{table}
\caption{Predicting Ex Post Covariances between between Stock Returns and Consumption Growth}
    \label{Tab6}
\centering
\renewcommand\arraystretch{1.2}
    \begin{tabular}{
          >{$}l<{$}|
     *{2}{>{\centering}p{41mm}|}
     *{2}{S[table-format=2.3]}}
\multicolumn{5}{l}{\textbf{Panel A: 1st stage regression}}                  \\ 
    \hline
\text{Dependent variable}
        &   \multicolumn{2}{l|}{Predictors} & {$F$-statistic} & {$P$-Value}    \\ 
    \hline
r^e_t   &   \mcc{$D/P_{t-1}$, $\mathit{SVAR}_{t-1}$, $\mathit{BM}_{t-1}$, 
                $\mathit{NTIS}_{t-1}$, $\mathit{LTY}_{t-1}$}  
            &   4.45    &   0.001                                           \\
\Delta c_{CE,t}
        &   \mcc{$\Delta c_{\mathit{CE},t-1}$, $\Delta c_{\mathit{CE},t-2}$,
                $\Delta c_{\mathit{CE},t-3}$, $r_{f,t-1}$}
            &   43.67   &   0.000                                           \\
\Delta c_{NIPA,t}
        &   \mcc{$\Delta c_{\mathit{NIPA},t-1}$, $\Delta c_{\mathit{NIPA},t-2}$,
                $\Delta c_{\mathit{NIPA},t-3}$, $r_{f,t-1}$}
            &   65.14   &   0.000                                           \\
\Delta c_{H,t}
        &   \mcc{$\Delta c_{H,t-1}$, $\Delta c_{H,t-2}$,
                $\Delta c_{H,t-3}$, $r_{f,t-1}$}
            &   19.11   &   0.000                                           \\
    \hline                                                                  
\mc{}   &   \mc{}   &   \mc{}   &   \mc{}   &   \mc{}                       \\
\multicolumn{5}{l}{\textbf{Panel B: 2nd stage regression}}                  \\
    \hline
\T      &   \mcc{Predictors}     &                   &                      \\
    \cline{2-3}
\text{Dependent variable}
    &   $\hat{\epsilon}_{r^e,t-1} \hat{\epsilon}_{\Delta c_{i},t-1}$
        &   $M/C_{i,t-1}$       & {$F$-statistic}     &   {$P$-Value}       \\
    \hline
\T\  \hat{\epsilon}_{r^e,t} \hat{\epsilon}_{\Delta c_{CE},t}
    & -0.143**
        &   \num{1.06e-5}       &   2.93            & 0.055                 \\
%\rowfont{\small}
        &   (-2.26)
            &   (0.85)          &                   &                       \\
\T\  \hat{\epsilon}_{r^e,t} \hat{\epsilon}_{\Delta c_{NIPA},t}
    & 0.108
        & \num{-9.27e-6}        &   1.34            &   0.264               \\
    & (1.64)
        &   (-0.23)             &                   &                       \\
\T\  \hat{\epsilon}_{r^e,t} \hat{\epsilon}_{\Delta c_{H},t}
    & -0.133**
        & \num{-2.65e-5}        &   2.28            &   0.105               \\
%\rowfont{\small}
    &   (-2.12)
        &   (-0.51)             &                   &                       \\
    \hline
    \end{tabular}%
\end{table}
\end{document}
  • booktabs通过使用包中的规则可以获得进一步的改进

\documentclass[12pt]{article}  %It can be article / report / and book
\usepackage[top=1.3in, bottom=1.3in, left=1in, right=1in]{geometry}
%\usepackage{setspace}
\usepackage{array, booktabs, multirow, rotating}
\usepackage{graphicx}
\usepackage{amsmath, amssymb, amsfonts}
\usepackage[table]{xcolor}
\usepackage{graphicx}
\usepackage{pgfplots}
\usetikzlibrary{snakes}
\usepackage{caption}
\usepackage{subcaption}

\usepackage{siunitx}% added

\def\T{\texttt{T}}
\newcommand\mc[1]{ \multicolumn{1}{l}{#1}}
\newcommand\mcc[1]{\multicolumn{2}{>{\raggedright}p{82mm}}{#1}}

\usepackage{lipsum}% dummy text

\begin{document}
    \begin{table}
\caption{Predicting Ex Post Covariances between between Stock Returns and Consumption Growth}
    \label{Tab6}
\centering
\renewcommand\arraystretch{1.2}
    \begin{tabular}{
          >{$}l<{$}
     *{2}{>{\centering}p{41mm}}
     *{2}{S[table-format=2.3]}}
\multicolumn{5}{l}{\textbf{Panel A: 1st stage regression}}                  \\ 
    \toprule
\text{Dependent variable}
        &   \multicolumn{2}{c}{Predictors} & {$F$-statistic} & {$P$-Value}    \\ 
    \midrule
r^e_t   &   \mcc{$D/P_{t-1}$, $\mathit{SVAR}_{t-1}$, $\mathit{BM}_{t-1}$, 
                $\mathit{NTIS}_{t-1}$, $\mathit{LTY}_{t-1}$}  
            &   4.45    &   0.001                                           \\
\Delta c_{CE,t}
        &   \mcc{$\Delta c_{\mathit{CE},t-1}$, $\Delta c_{\mathit{CE},t-2}$,
                $\Delta c_{\mathit{CE},t-3}$, $r_{f,t-1}$}
            &   43.67   &   0.000                                           \\
\Delta c_{NIPA,t}
        &   \mcc{$\Delta c_{\mathit{NIPA},t-1}$, $\Delta c_{\mathit{NIPA},t-2}$,
                $\Delta c_{\mathit{NIPA},t-3}$, $r_{f,t-1}$}
            &   65.14   &   0.000                                           \\
\Delta c_{H,t}
        &   \mcc{$\Delta c_{H,t-1}$, $\Delta c_{H,t-2}$,
                $\Delta c_{H,t-3}$, $r_{f,t-1}$}
            &   19.11   &   0.000                                           \\
    \midrule
    \addlinespace[3ex]                                                                 
\multicolumn{5}{l}{\textbf{Panel B: 2nd stage regression}}                  \\
    \midrule
\T      &   \multicolumn{2}{c}{Predictors}      
                                &                   &                      \\
    \cmidrule(lr){2-3}
\text{Dependent variable}
    &   $\hat{\epsilon}_{r^e,t-1} \hat{\epsilon}_{\Delta c_{i},t-1}$
        &   $M/C_{i,t-1}$       & {$F$-statistic}   &   {$P$-Value}       \\
    \midrule
\T\  \hat{\epsilon}_{r^e,t} \hat{\epsilon}_{\Delta c_{CE},t}
    & -0.143**
        &   \num{1.06e-5}       &   2.93            & 0.055                 \\
        &   (-2.26)
            &   (0.85)          &                   &                       \\
\T\  \hat{\epsilon}_{r^e,t} \hat{\epsilon}_{\Delta c_{NIPA},t}
    & 0.108
        & \num{-9.27e-6}        &   1.34            &   0.264               \\
%\rowfont{\small}
    & (1.64)
        &   (-0.23)             &                   &                       \\
\T\  \hat{\epsilon}_{r^e,t} \hat{\epsilon}_{\Delta c_{H},t}
    & -0.133**
        & \num{-2.65e-5}        &   2.28            &   0.105               \\
    &   (-2.12)
        &   (-0.51)             &                   &                       \\
    \bottomrule
    \end{tabular}%
\end{table}
\end{document}

在此处输入图片描述

相关内容