如何让表格列的宽度相同?

如何让表格列的宽度相同?

在此处输入图片描述我制作了一个表格,但列宽不均匀。我尝试了很多方法,但仍然无法使列宽均匀。奇怪的是,我还有很多其他具有相同样式的表格,它们的列宽相同。我真的很困惑。我很感激任何关于这个问题的帮助。谢谢。

\documentclass[english,authoryear,12pt]{article}

\usepackage{caption}
\captionsetup[table]{justification=centering, labelsep=newline, font=bf, skip=1ex} 

\usepackage{tabularx,booktabs} 
\usepackage{tabularray}

\usepackage{array}
\usepackage{longtable}
\usepackage[english]{babel}
\usepackage{epstopdf}
\usepackage{epsfig}
%\usepackage{geometry}
\usepackage{lscape}
\usepackage{pdflscape}
\usepackage{rotating}
\usepackage{rotate}
\usepackage{multirow}
\usepackage{parskip}
\usepackage[capposition=top]{floatrow}
\usepackage{placeins}
\usepackage{booktabs}
\newcommand{\tabitem}{~~\llap{\textbullet}~~}
\usepackage{adjustbox}
\usepackage{url}
\usepackage{subfigure}
\usepackage{threeparttable}
\usepackage{setspace}
\usepackage{mathrsfs}
\usepackage{authblk}
\usepackage[authoryear,round]{natbib}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc} 
\usepackage{mathtools} 
\usepackage{float}
\usepackage{floatrow}
\usepackage{siunitx}
\usepackage{caption}
\usepackage[colorlinks,citecolor=red,urlcolor=blue,bookmarks=false,hypertexnames=true]{hyperref} 
\usepackage{soul}
\usepackage[toc,page]{appendix} 
\bibpunct{(}{)}{;}{a}{,}{,}
\bibliographystyle{econ}


\renewcommand\Authfont{\small}
\renewcommand\Affilfont{\itshape\footnotesize}
\renewcommand{\baselinestretch}{1}
\sloppy
\setcounter{MaxMatrixCols}{10}

\setlength{\textheight}{215mm}
\setlength{\textwidth}{160mm}
\setlength{\oddsidemargin}{0pt}
\setlength{\topmargin}{-20pt}
\setlength{\headsep}{35pt}
\setlength{\textwidth}{160mm}
\setlength{\evensidemargin}{0pt}
\setlength{\headheight}{12pt}
\setlength{\parindent}{0.5cm}
\setlength\parskip{0.1in}
\providecommand{\lessgtr}{\stackrel{<}{>}}
\IfFileExists{pslatex.sty}{
    \usepackage{pslatex}
}{}
%\input{tcilatex}
\DeclareUnicodeCharacter{2212}{-} 


\begin{document}
    \title{Title A}
    



\pagebreak{}
\clearpage
\newpage

\begin{table}[H]\footnotesize\setlength{\tabcolsep}{3pt}
    \caption{\textbf{Optimism} \label{tab:optimism}}
    
    \begin{tablenotes}[flushleft]
        \footnotesize 
        \item We report the t-statistics in the parenthesis. *, **, and *** represent significance at the 10\%, 5\% and 1\% levels, respectively.    
        
    \end{tablenotes}
    \smallskip
    \begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}l*{3}{c}}
        \toprule
        &\multicolumn{3}{c}{  Hold/Underperform/Sell Recommendation}                     \\
        \cmidrule (lr){2-4}  \noalign{\smallskip}
        &\multicolumn{1}{c}{(1)}   &\multicolumn{1}{c}{(2)}   &\multicolumn{1}{c}{(3)}    \\
        \midrule 
        
        &       &       &  \\
        X1 & -0.022*** & -0.021*** & -0.019*** \\
        & (-3.274) & (-3.257) & (-3.042) \\
        X2 & 0.007*** & 0.007*** & 0.008*** \\
        & (3.005) & (3.161) & (5.149) \\
        X3 & 0.008 & 0.016 & 0.017 \\
        & (0.123) & (0.250) & (0.299) \\
        X4 & 0.039* & 0.039* & 0.034* \\
        & (1.830) & (1.823) & (1.803) \\
        X5 & 0.004 & 0.005 & 0.004 \\
        & (0.826) & (1.058) & (1.056) \\

        &       &       &  \\
        Year Fixed Effects & YES   & YES   & YES  \\
        Firm Fixed Effects & YES   & YES   & YES  \\
        &       &       &        \\
        Observations & 71,060 & 71,060 & 71,060 \\
        
        \bottomrule
    \end{tabular*}
    
\end{table}

\pagebreak{}
\clearpage
\newpage


\end{document}

答案1

一些建议:

  • 将三个数据列中的数字对齐到各自的小数点标记上。这可以使用包D提供的列类型来完成dcolumn。采用此方法会自动使列宽相等。

  • 在标题材料上施加更多的视觉结构。

  • 使用宏\addlinespace(由包提供booktabs)而不是全空行来在需要时增加垂直间距。

在此处输入图片描述

\documentclass{article} % or some other suitable document class 
\usepackage{caption}
\captionsetup[table]{justification=centering, 
           labelsep=newline, 
           font=bf, skip=1ex} 
\usepackage{booktabs,threeparttable} 
\usepackage[T1]{fontenc}

%new code:
\usepackage{dcolumn}
\newcolumntype{d}[1]{D..{#1}}
\newcommand\mc[1]{\multicolumn{1}{c}{#1}} % handy shortcut macros
\newcommand\mcx[1]{\multicolumn{1}{c@{}}{#1}} % for use in final column

\begin{document}

\begin{table}[ht]

\centering
\begin{threeparttable}
\footnotesize % why?
\caption{Optimism} \label{tab:optimism}

\begin{tabular}{@{} l *{3}{d{4.6}} @{}}
   \toprule
   &\multicolumn{3}{c@{}}{Recommendation} \\
   \cmidrule(l){2-4}  
   & \mc{Hold} & \mc{Underperform} & \mcx{Sell} \\
   & \mc{(1)} & \mc{(2)} & \mcx{(3)} \\
   \midrule 

   X1 & -0.022^{***} & -0.021^{***} & -0.019^{***} \\
      & (-3.274)     & (-3.257)     & (-3.042)     \\ \addlinespace
   X2 & 0.007^{***}  & 0.007^{***}  & 0.008^{***}  \\
      & (3.005)      & (3.161)      & (5.149)      \\ \addlinespace
   X3 & 0.008     & 0.016     & 0.017     \\
      & (0.123)   & (0.250)   & (0.299)   \\ \addlinespace
   X4 & 0.039^{*} & 0.039^{*} & 0.034^{*} \\
      & (1.830)   & (1.823)   & (1.803)   \\ \addlinespace
   X5 & 0.004     & 0.005     & 0.004     \\
      & (0.826)   & (1.058)   & (1.056)   \\ \addlinespace
   Year FEs & \mc{Y}   & \mc{Y}   & \mcx{Y}\\
   Firm FEs & \mc{Y}   & \mc{Y}   & \mcx{Y}\\ 
   No.\ of Obs. & \mc{71,060} & \mc{71,060} & \mcx{71,060} \\
   \bottomrule
\end{tabular}

\smallskip
We report $t$-statistics in parentheses. *, **, and *** denote significance at the 10\%, 5\%, and 1\% levels, respectively.    
\end{threeparttable}

\end{table}

\end{document}

答案2

作为对 @mico 的精彩回答 (+1) 的补充,使用该tabularray包。它的表前言较长,但表体较短:

\documentclass{article}
\usepackage{tabularray}
\UseTblrLibrary{booktabs,siunitx}
\ExplSyntaxOn
\NewChildSelector{eachtwo}
  {
    \int_step_inline:nnnn {5}{2}{\l_tblr_childs_total_tl}
      { \clist_put_right:Nn \l_tblr_childs_clist {##1} }
  }
\ExplSyntaxOff
\usepackage{caption}
\captionsetup[table]{justification=centering,
                     labelsep=newline,
                     font=bf,
                     }

\begin{document}
    \begin{table}[ht]
    \centering
\NewTblrTheme{captionof}%
{
    \DefTblrTemplate{caption}{default}%
    {\addtocounter{table}{-1}%
     \captionof{table}{\InsertTblrText{caption}}}
}
\SetTblrStyle{remark}{font=\footnotesize}
\captionsetup[table]{skip=-0.5ex}
\sisetup{
    input-open-uncertainty =,
    input-close-uncertainty=,
    table-align-text-before=false,
    table-format={(}-1.3{***}
        }
\begin{talltblr}[
  theme = captionof,
caption = {Optimism},
  label = {tab:optimism},
 remark{Note} = {We report $t$-statistics in parentheses.
                *, **, and *** denote significance at the
                \qty{10}{\%}, \qty{5}{\%}, and \qty{1}{\%}
                levels, respectively.}
                ]{colspec = {@{} l *{3}{Q[c, si]} @{}},
                  row{1-2}= {guard},
                  row{4-Z}= {rowsep=0 pt},
                  row{eachtwo} = {abovesep=1ex},
                  }
   \toprule
   &\SetCell[c=3]{c}    Recommendation  \\
   \cmidrule{2-4}
   & {Hold\\ (1)}   & {Underperform\\ (2)}  & {Sell\\ (3)}  \\
   \midrule
X1 & -0.022\TblrNote{***}
                    & -0.021\TblrNote{***}  & -0.019\TblrNote{***}  \\
    & (-3.274)      & (-3.257)              & (-3.042)              \\
X2  & 0.007\TblrNote{***}
                    & 0.007\TblrNote{***}   & 0.008\TblrNote{***}   \\
    & (3.005)       & (3.161)               & (5.149)               \\
X3  & 0.008         & 0.016                 & 0.017                 \\
    & (0.123)       & (0.250)               & (0.299)               \\
X4  & 0.039\TblrNote{*}
                    & 0.039\TblrNote{*}     & 0.034\TblrNote{*}     \\
    & (1.830)       & (1.823)               & (1.803)               \\
X5  & 0.004         & 0.005                 & 0.004                 \\
    & (0.826)       & (1.058)               & (1.056)               \\

Year FEs    &   {Y}     &   {Y}             &   {Y}                 \\
Firm FEs    &   {Y}     &   {Y}             &   {Y}                 \\
No. of Obs. & {71,060}  & {71,060}          & {71,060}              \\
   \bottomrule
\end{talltblr}
    \end{table}
\end{document}

在此处输入图片描述

相关内容