表格对齐不正确,没有在应有的位置开始新行

表格对齐不正确,没有在应有的位置开始新行

我需要帮助来正确编码表格。行从错误的列开始。这是我的代码:

\begin{table}[htbp!]
  \centering
  \small % Reduce font size for table content
  \caption{\textbf{First Day Returns by subgroup and IPO Cyclically}}
  \adjustbox{max width=\textwidth}{
    \begin{tabular}{p{2cm}>{\raggedleft}p{1cm}>{\raggedright}p{1cm}>{\raggedleft}p{1cm}>{\raggedright}p{1cm}>{\raggedleft}p{1cm}>{\raggedright}p{1cm}}
      \toprule\toprule
      \multicolumn{7}{p{\dimexpr\textwidth-\tabcolsep\relax}}{
        \raggedright
        The total sample includes 825 IPOs comprising of 171 PE, 182 VC and 472 NS. The table present the results from testing if the first-day returns across all three subgroups are significantly different from zero. The test is conducted using a two sided t-test.  
      } \\
      \midrule
    \textbf{Subgroups} & \textbf{PE} & \textbf{NS} & \textbf{PE} & \textbf{VC} & \textbf{NS} & \textbf{VC} \\
    \midrule
    Mean (\%) & 9 & 11 & 9 & 8 & 11 & 8 \\
    P-Value &   \multicolumn{2}{c}{0,57} &  \multicolumn{2}{c}{0,47} &  \multicolumn{2}{c}{0,84} \\
      \bottomrule\bottomrule
    \end{tabular}
  }
  \label{table:7.2}
\end{table}

结果如下:

在此处输入图片描述

答案1

主要问题\raggedright在于表格规范:除了最后一列之外,它在所有列中都有效,这就是输出奇怪的原因。

我认为您不应该将表格加宽到文本宽度,但无论如何使用adjustbox都不是办法。

\documentclass{article}
\usepackage{booktabs,array}
\usepackage{caption}

\captionsetup{font=bf}

\newlength{\templength}

\begin{document}

\begin{table}[htbp!]
\centering

\caption{First Day Returns by subgroup and IPO Cyclically}
\label{table:7.2}

\settowidth{\templength}{\textbf{Subgroups}}
\setlength{\tabcolsep}{\dimexpr(\textwidth-\templength-6cm)/6\relax}

\begin{tabular}{@{} l *{3}{w{c}{1cm}@{}w{c}{1cm}} @{}}
\toprule
\multicolumn{7}{@{}p{\textwidth}@{}}{%
  The total sample includes 825 IPOs comprising of 171 PE, 182 VC and 472 NS. 
  The table present the results from testing if the first-day returns across
  all three subgroups are significantly different from zero. The test is
  conducted using a two sided t-test.} \\
\midrule
\textbf{Subgroups} & \textbf{PE} & \textbf{NS} & \textbf{PE}
   & \textbf{VC} & \textbf{NS} & \textbf{VC} \\
\midrule
Mean (\%) & 9 & 11 & 9 & 8 & 11 & 8 \\
P-Value &   \multicolumn{2}{c}{0,57} &  \multicolumn{2}{c}{0,47} &
  \multicolumn{2}{c@{}}{0,84} \\
\bottomrule
\end{tabular}

\end{table}

\end{document}

根据最上面的段落,我们需要做一些测量。

在此处输入图片描述

或者,将描述移至表格下方。

\documentclass{article}
\usepackage{booktabs,array}
\usepackage{caption}

\captionsetup{font=bf}

\begin{document}

\begin{table}[htbp!]

\caption{First Day Returns by subgroup and IPO Cyclically}
\label{table:7.2}

{\centering
\begin{tabular}{@{} l *{3}{w{c}{1cm}@{}w{c}{1cm}} @{}}
\toprule
\textbf{Subgroups} & \textbf{PE} & \textbf{NS} & \textbf{PE}
   & \textbf{VC} & \textbf{NS} & \textbf{VC} \\
\midrule
Mean (\%) & 9 & 11 & 9 & 8 & 11 & 8 \\
P-Value &   \multicolumn{2}{c}{0,57} &  \multicolumn{2}{c}{0,47} &
  \multicolumn{2}{c@{}}{0,84} \\
\bottomrule
\end{tabular}

}
\bigskip

The total sample includes 825 IPOs comprising of 171 PE, 182 VC and 472 NS. 
The table present the results from testing if the first-day returns across
all three subgroups are significantly different from zero. The test is
conducted using a two sided t-test.

\end{table}

\end{document}

在此处输入图片描述

答案2

我不会调整表格大小,因为这会导致表格中的字体大小不一致。如果您希望表格宽度等于\textwidth表格tabular*,则可以使用tabularxtabularray包。使用后者,您的表格代码可以是:

\documentclass{article}
\usepackage[skip=1ex, font=bf]{caption}
\usepackage{tabularray}
\UseTblrLibrary{booktabs}


\begin{document}
    \begin{table}[htbp!]
\caption{First Day Returns by subgroup and IPO Cyclically}
\label{table:7.2}

\begin{tblr}{colspec = {@{} l *{6}{X[c]} @{} },
             row{2}  = {font=\bfseries},
             hspan = minimal
             }   
    \toprule
\SetCell[c=7]{j}
The total sample includes 825 IPOs comprising of 171 PE, 182 VC and 472 NS. The table present the results from testing if the first-day returns across all three subgroups are significantly different from zero. The test is conducted using a two sided $t$-test.
    &   &   &   &   &   &   \\
    \midrule
Subgroups   & PE    & NS    & PE    & VC    & NS    & VC                \\
    \midrule
Mean (\%)   & 9     & 11    & 9     & 8     & 11    & 8                 \\
P-Value     &   \SetCell[c=2]{c}    0,57
                    &       &   \SetCell[c=2]{c}    0,47
                                    &       &   \SetCell[c=2]{c} 0,84   \\
    \bottomrule
\end{tblr}
    \end{table}
\end{document}

在此处输入图片描述

相关内容