如何在 tabularx 环境中的单元格中换行长文本

如何在 tabularx 环境中的单元格中换行长文本

我在 tabularx 环境中遇到了自动文本换行的问题。

我遇到了问题

\gmc{14}{l}{Characteristic 1: Cross-sectional overlap 
in month-over-month regional real estate price changes
(Spearman/Pearson correlations below/above the diagonal)}

请帮忙。谢谢!

\documentclass[11pt]{article}
\usepackage{setspace,amssymb,amsmath}
\usepackage[tablename=TABLE,labelsep=newline,
aboveskip=0pt,font=bf,justification=centering]{caption}
\usepackage{booktabs,tabularx}
\usepackage[margin=1in]{geometry}
\usepackage[autostyle]{csquotes}
\usepackage[table]{xcolor}

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

\begin{document}

\newpage
\begingroup % keep any font size changes local to group
%\setlength\tabcolsep{2pt} % default value: 6pt
\captionof{table}{U.S. Corporate Employees and the Supply of Real Estate Properties Available for Sale}
\singlespacing
\footnotesize

\begin{tabularx}{\textwidth}{@{}l YYYYYYYYYYYYY@{}}
    \toprule
    \gmc{14}{l}{Characteristic 1: Cross-sectional overlap in month-over-month regional real estate price changes (Spearman/Pearson correlations below/above the diagonal)} \\\hline
    &&  region1 & region2&  region3&    region4&    region5&    region6&    region7&    region8&    region9&    region10&   region11&   region12 \\\cline{3-14}
    region1&    DC-Washington&  1.000&  0.585&  0.684&  0.592&  0.782&  0.777&  0.490&  0.695&  0.696&  0.527&  0.559&  0.632 \\
    region2&    MI-Detroit& 0.526&  1.000&  0.796&  0.504&  0.512&  0.561&  0.569&  0.791&  0.636&  0.475&  0.570&  0.502 \\
    region3&    MN-Minneapolis& 0.665&  0.649&  1.000&  0.597&  0.592&  0.642&  0.669&  0.804&  0.692&  0.510&  0.579&  0.544\\
    region4&    OH-Cleveland&   0.571&  0.487&  0.517&  1.000&  0.444&  0.572&  0.661&  0.645&  0.597&  0.571&  0.604&  0.581\\
    region5&    CA-San Diego&   0.766&  0.479&  0.583&  0.435&  1.000&  0.771&  0.473&  0.500&  0.533&  0.415&  0.441&  0.590\\
    region6&    CA-San Francisco&   0.754&  0.486&  0.531&  0.511&  0.754&  1.000&  0.525&  0.611&  0.595&  0.506&  0.544&  0.699\\
    region7&    CO-Denver&  0.386&  0.521&  0.606&  0.594&  0.380&  0.352&  1.000&  0.536&  0.512&  0.525&  0.521&  0.622\\
    region8&    IL-Chicago& 0.724&  0.622&  0.694&  0.600&  0.509&  0.548&  0.396&  1.000&  0.646&  0.584&  0.590&  0.642\\
    region9&    MA-Boston&  0.683&  0.634&  0.704&  0.578&  0.546&  0.584&  0.508&  0.617&  1.000&  0.490&  0.425&  0.522\\
    region10&   NC-Charlotte&   0.444&  0.349&  0.356&  0.524&  0.313&  0.380&  0.424&  0.481&  0.462&  1.000&  0.596&  0.648\\
    region11&   OR-Portland&    0.446&  0.421&  0.379&  0.559&  0.320&  0.371&  0.404&  0.461&  0.338&  0.489&  1.000&  0.720\\
    region12&   WA-Seattle& 0.639&  0.373&  0.459&  0.607&  0.581&  0.664&  0.558&  0.596&  0.535&  0.573&  0.629&  1.000\\
    region13&   AZ-Phoenix& 0.600&  0.441&  0.493&  0.313&  0.577&  0.587&  0.380&  0.489&  0.499&  0.371&  0.427&  0.518\\
    region14&   CA-Los Angeles& 0.802&  0.480&  0.569&  0.401&  0.809&  0.748&  0.211&  0.586&  0.534&  0.357&  0.369&  0.622\\
    region15&   TX-Dallas&  0.566&  0.425&  0.584&  0.732&  0.432&  0.551&  0.825&  0.580&  0.666&  0.715&  0.644&  0.640\\
    region16&   FL-Miami&   0.682&  0.367&  0.517&  0.286&  0.546&  0.500&  0.306&  0.505&  0.417&  0.233&  0.357&  0.476\\
    region17&   FL-Tampa&   0.678&  0.436&  0.570&  0.359&  0.534&  0.525&  0.325&  0.554&  0.509&  0.305&  0.461&  0.579\\
    region18&   GA-Atlanta& 0.604&  0.582&  0.606&  0.670&  0.521&  0.584&  0.698&  0.662&  0.683&  0.623&  0.570&  0.607\\
    region19&   NV-Las Vegas&   0.471&  0.396&  0.411&  0.281&  0.558&  0.421&  0.214&  0.392&  0.319&  0.276&  0.434&  0.479\\
    region20&   NY-New York&    0.744&  0.589&  0.699&  0.428&  0.483&  0.428&  0.288&  0.688&  0.764&  0.356&  0.299&  0.528\\
    \bottomrule
\end{tabularx}   

\medskip\small \newpage  \hrule \vspace{0.05in}  
Notes: The table reports results from analysis of geographic overlaps in real estate price changes and accounting profitability changes across Case-Shiller regions. Panel A (B) provides Spearman/Pearson correlations below/above the diagonal in month-over-month (year-over-year) real estate price changes across regions. Panel C \vspace{0.05in}\hrule \par
\endgroup

\结束{文档}

答案1

除了更改第一个标题行的列类型(从到l--在您的答案--)>{\hsize=\textwidth}X,您还应该

  • 避免在 Region1/Region2/etc 标题中产生难看的重叠,这可能会导致标题无法读取;并且

  • 找到一种方法来避免在 中使用主要表格材料\footnotesize。在下面的代码中,简化标题结构并减少列间空白量允许使用 来\small作为表格材料。

在此处输入图片描述

\documentclass[11pt]{article}
\usepackage{setspace,amssymb,amsmath}
\usepackage[tablename=TABLE,labelsep=newline,
aboveskip=0pt,font=bf,justification=centering]{caption}
\usepackage{booktabs,tabularx}
\usepackage[margin=1in]{geometry}
\usepackage[autostyle]{csquotes}
\usepackage[table]{xcolor}

\newcolumntype{Y}{>{\centering\arraybackslash}X}

\doublespacing

\begin{document}


\begingroup % keep any font size changes local to group
\singlespacing
\captionof{table}{U.S. Corporate Employees and Supply of Real Estate Properties Available for Sale}

\small
\setlength\tabcolsep{3pt} % default: 6pt

\begin{tabularx}{\textwidth}{@{} ll *{12}{Y} @{}}
\toprule
\multicolumn{14}{@{}p{\textwidth}@{}}{Characteristic 1: Cross-sectional overlap in month-over-month regional real estate price changes (Spearman\slash Pearson correlations below\slash above the diagonal)} \\
\midrule
&& \multicolumn{12}{c@{}}{Region}\\
\cmidrule(l){3-14}
&& 1 & 2& 3& 4& 5& 6& 7& 8& 9& 10& 11& 12 \\
\cmidrule(l){3-14}
1& DC-Washington& 1.000& 0.585& 0.684& 0.592& 0.782& 0.777& 0.490& 0.695& 0.696& 0.527& 0.559& 0.632 \\
2& MI-Detroit& 0.526& 1.000& 0.796& 0.504& 0.512& 0.561& 0.569& 0.791& 0.636& 0.475& 0.570& 0.502 \\
3& MN-Minneapolis& 0.665& 0.649& 1.000& 0.597& 0.592& 0.642& 0.669& 0.804& 0.692& 0.510& 0.579& 0.544\\
4& OH-Cleveland& 0.571& 0.487& 0.517& 1.000& 0.444& 0.572& 0.661& 0.645& 0.597& 0.571& 0.604& 0.581\\
5& CA-San Diego& 0.766& 0.479& 0.583& 0.435& 1.000& 0.771& 0.473& 0.500& 0.533& 0.415& 0.441& 0.590\\
6& CA-San Francisco& 0.754& 0.486& 0.531& 0.511& 0.754& 1.000& 0.525& 0.611& 0.595& 0.506& 0.544& 0.699\\
7& CO-Denver& 0.386& 0.521& 0.606& 0.594& 0.380& 0.352& 1.000& 0.536& 0.512& 0.525& 0.521& 0.622\\
8& IL-Chicago& 0.724& 0.622& 0.694& 0.600& 0.509& 0.548& 0.396& 1.000& 0.646& 0.584& 0.590& 0.642\\
9& MA-Boston& 0.683& 0.634& 0.704& 0.578& 0.546& 0.584& 0.508& 0.617& 1.000& 0.490& 0.425& 0.522\\
10& NC-Charlotte& 0.444& 0.349& 0.356& 0.524& 0.313& 0.380& 0.424& 0.481& 0.462& 1.000& 0.596& 0.648\\
11& OR-Portland& 0.446& 0.421& 0.379& 0.559& 0.320& 0.371& 0.404& 0.461& 0.338& 0.489& 1.000& 0.720\\
12& WA-Seattle& 0.639& 0.373& 0.459& 0.607& 0.581& 0.664& 0.558& 0.596& 0.535& 0.573& 0.629& 1.000\\
13& AZ-Phoenix& 0.600& 0.441& 0.493& 0.313& 0.577& 0.587& 0.380& 0.489& 0.499& 0.371& 0.427& 0.518\\
14& CA-Los Angeles& 0.802& 0.480& 0.569& 0.401& 0.809& 0.748& 0.211& 0.586& 0.534& 0.357& 0.369& 0.622\\
15& TX-Dallas& 0.566& 0.425& 0.584& 0.732& 0.432& 0.551& 0.825& 0.580& 0.666& 0.715& 0.644& 0.640\\
16& FL-Miami& 0.682& 0.367& 0.517& 0.286& 0.546& 0.500& 0.306& 0.505& 0.417& 0.233& 0.357& 0.476\\
17& FL-Tampa& 0.678& 0.436& 0.570& 0.359& 0.534& 0.525& 0.325& 0.554& 0.509& 0.305& 0.461& 0.579\\
18& GA-Atlanta& 0.604& 0.582& 0.606& 0.670& 0.521& 0.584& 0.698& 0.662& 0.683& 0.623& 0.570& 0.607\\
19& NV-Las Vegas& 0.471& 0.396& 0.411& 0.281& 0.558& 0.421& 0.214& 0.392& 0.319& 0.276& 0.434& 0.479\\
20& NY-New York& 0.744& 0.589& 0.699& 0.428& 0.483& 0.428& 0.288& 0.688& 0.764& 0.356& 0.299& 0.528\\
\bottomrule
\end{tabularx}   

\medskip  
Notes: The table reports results from analysis of geographic overlaps in real estate price changes and accounting profitability changes across Case-Shiller regions. Panel A (B) provides Spearman/Pearson correlations below/above the diagonal in month-over-month (year-over-year) real estate price changes across regions. Panel C \dots \par

\medskip
\hrule 
\endgroup

\end{document}

答案2

我把需要的行改为

\gmc{14}{>{\hsize=\textwidth}X}{Characteristic 1: 
Cross-sectional overlap in month-over-month regional
real estate price changes (Spearman/Pearson correlations
below/above the diagonal)} \\\hline

并且它有效!!

相关内容