Tabularx 中的居中功能不起作用

Tabularx 中的居中功能不起作用

我正在尝试使用 来居中列
\newcolumntype{Y}{>{\centering\arraybackslash}X}。但是在以下示例中,它不起作用。

\documentclass[11pt]{article}
\usepackage{setspace}
\usepackage{amssymb,colortbl}
\usepackage[capposition=top]{floatrow}
\usepackage[tablename=TABLE,labelsep=newline,aboveskip=0pt,bf, justification = centering]{caption}
\usepackage{clipboard}
\usepackage{booktabs}
\usepackage[svgnames]{xcolor}
\usepackage[capposition=top]{floatrow}
\usepackage{ltablex}
\usepackage{threeparttablex}
\usepackage{fancyvrb}

\newcolumntype{Y}{>{\centering\arraybackslash}X}
\newcommand{\gmc}[2]{\multicolumn{#1}{@{}#2@{}}}
\newcommand*{\tabnospace}{\item \noindent \hspace{-0.05in}}

\begin{document}
\begin{ThreePartTable}    
\footnotesize
\setlength\LTleft{0pt}
\setlength\LTright{0pt}
\renewcommand\TPTminimum{\textwidth}

\begin{TableNotes}[flushleft]       
\small      
\tabnospace 
Notes: The table reports results from regression models of future forecast errors of real estate price changes on the corresponding-region accounting profitability change. Forecast errors are actual realizations of real estate price changes minus the corresponding-period forecasts from Econoday and Zillow. Table 1 provides more details on the variables and the sample. \hrule
\end{TableNotes}        

\singlespacing  
\captionof{table}{\textbf{How is Regional Accounting Information Processed by Real Estate Forecasters?}}
\begin{tabularx}{\textwidth}{@{\extracolsep{\fill}}XYYY@{\extracolsep{\fill}}}
\toprule
\endfirsthead\endhead
\bottomrule\insertTableNotes
\endlastfoot
\gmc{4}{l}{Panel A. Econoday forecasts} \\\hline
& \gmc{3}{c}{Future Forecast error of regional real estate price change} \\\hline
& Estimate & Standard Error & t-statistic \\\hline
\rowcolor{gray!25}$\Delta Prof_{region}$ &  0.100&  0.046&  2.165\\
Intercept & 0.000&  0.001&  0.147 \\
Adjusted $R^2$ &    0.154        \\\\\hline
\gmc{4}{l}{Panel A. Zillow forecasts} \\\hline  
&Estimate&  Standard Error& t-statistic\\
\rowcolor{gray!25}  $\Delta Prof_{region}$ &    0.068&  0.029&  2.389 \\
Intercept&  0.000&  0.000&  0.347\\\\
Adjusted $R^2$ &    0.145        \\
\end{tabularx}   
\end{ThreePartTable}

\end{document}

答案1

您似乎混淆了来自、、longtable和其他环境的各种概念和方法。要理清这些混乱局面并找出列内容未居中的原因相当困难。tabularxtabular*

我建议您通过仅使用一个环境以及适合该环境的命令来简化代码。在下面的示例中,我使用了一个tabularx环境。我还建议您重新组织表格材料的结构,例如按照下面的思路。

在此处输入图片描述

\documentclass[11pt]{article}
\usepackage{setspace,amssymb}
\usepackage[tablename=TABLE,labelsep=newline,
   aboveskip=0pt,font=bf,justification=centering]{caption}
\usepackage{booktabs,tabularx}

\newcolumntype{Y}{>{\centering\arraybackslash}X}
\newcommand{\gmc}[3]{\multicolumn{#1}{@{}#2@{}}{#3}}

\begin{document}

\begingroup % keep any font size changes local to group
\setlength\tabcolsep{2pt} % default value: 6pt
\captionof{table}{How is Regional Accounting Information Processed by Real Estate Forecasters?}

\begin{tabularx}{\textwidth}{@{}lYYY@{}}
\toprule
& \multicolumn{3}{>{\hsize=3\hsize}Y}{Future forecast error of regional real estate price change} 
\\\cmidrule(l){2-4}
& Estimate & Standard Error & $t$-statistic \\\midrule
\gmc{4}{l}{Panel A\@. Econoday forecasts} \\\addlinespace
$\Delta \textit{Prof}_{\textit{region}}$ &  0.100&  0.046&  2.165\\
Intercept & 0.000&  0.001&  0.147 \\[1ex]
Adjusted $R^2$ &    0.154        \\[3ex]
\gmc{4}{l}{Panel B\@. Zillow forecasts} \\\addlinespace  
$\Delta \textit{Prof}_{\textit{region}}$ &  0.068&  0.029&  2.389 \\
Intercept              &  0.000&  0.000&  0.347\\[1ex]
Adjusted $R^2$ &    0.145        \\
\bottomrule
\end{tabularx}   

\medskip\small      
Notes: The table reports results from regression models of future forecast errors of real estate price changes on the corresponding-region accounting profitability change. Forecast errors are actual realizations of real estate price changes minus the corresponding-period forecasts from Econoday and Zillow. Table~1 provides more details on the variables and the sample. \par
\endgroup


\end{document}

相关内容