大家好,我需要让下面的表格具有某些属性,以便适合页面。然后让列间距均匀,即使这意味着要拆分长列标签。
\documentclass[12pt]{article} %
\usepackage{booktabs}% http://ctan.org/pkg/booktabs
\usepackage{tabularx}% http://ctan.org/pkg/tabularx
\begin{document}
\begin{table}[htbp]
\centering
\caption{Descriptive statistics of country-level yearly covariates}
\begin{tabular}{rccc|ccc}
\addlinespace
\toprule
& \multicolumn{3}{c}{Countries experiencing spont. events of disturbance } & \multicolumn{3}{c}{Countries not experiencing spont. events of disturbance } \\
\midrule
& Obs & Mean & Std Dev. & Obs & Mean & Std. Dev \\
\hline
Urban population (percent) & 525 & 32.527 & 13.186 & 273 & 30.994 & 11.883 \\
GDP per capita (constant, USD, year 2000) & 462 & 643.516 & 700.011 & 270 & 488.737 & 480.186 \\
Democracy indicator (Binary) & 474 & 0.409 & 0.492 & 242 & 0.178 & 0.383 \\
Internet penetration (users/100 of population) & 418 & 2.739 & 4.598 & 213 & 2.916 & 5.954 \\
Cellphone subscribers (users/100 of population) & 524 & 10.857 & 20.657 & 270 & 12.015 & 24.364 \\
\bottomrule
\end{tabular}%
\label{covariates}%
\end{table}%
\end{document}
答案1
这是使表格适合的一种方法:
- 用于
>{\raggedright}m{3.0cm}
第一列。这会使该列具有固定宽度,并使内容垂直居中。 - 将标题分成几行。
- 我还添加了一些
\hrule
内容以使行更加突出。
代码:
\documentclass[12pt]{article} %
\usepackage{booktabs}% http://ctan.org/pkg/booktabs
\usepackage{tabularx}% http://ctan.org/pkg/tabularx
\begin{document}
\begin{table}[htbp]
\centering
\caption{Descriptive statistics of country-level yearly covariates}
\begin{tabular}{>{\raggedright}m{3.0cm}ccc|ccc}
\addlinespace
\toprule
& \multicolumn{3}{c}{Countries experiencing} & \multicolumn{3}{c}{Countries not experiencing} \\
& \multicolumn{3}{c}{spont. events } & \multicolumn{3}{c}{spont. events} \\
& \multicolumn{3}{c}{of disturbance } & \multicolumn{3}{c}{of disturbance } \\
\midrule
& Obs & Mean & Std Dev. & Obs & Mean & Std. Dev \\
\hline
Urban population (percent) & 525 & 32.527 & 13.186 & 273 & 30.994 & 11.883 \\\hrule
GDP per capita (constant, USD, year 2000) & 462 & 643.516 & 700.011 & 270 & 488.737 & 480.186 \\\hrule
Democracy indicator (Binary) & 474 & 0.409 & 0.492 & 242 & 0.178 & 0.383 \\\hrule
Internet penetration (users/100 of population) & 418 & 2.739 & 4.598 & 213 & 2.916 & 5.954 \\\hrule
Cellphone subscribers (users/100 of population) & 524 & 10.857 & 20.657 & 270 & 12.015 & 24.364 \\
\bottomrule
\end{tabular}%
\label{covariates}%
\end{table}%
\end{document}
答案2
\documentclass[12pt]{article} %
\usepackage{tabularx,booktabs}
\usepackage{ragged2e}
\renewcommand\tabularxcolumn[1]{m{#1}}
\begin{document}
\noindent
\begin{tabularx}{\linewidth}{@{}>{\RaggedRight}Xcrr|crr @{}}
\addlinespace
\toprule
& \multicolumn{3}{p{4.75cm}}{\RaggedRight Countries experiencing spont. events of disturbance}
& \multicolumn{3}{p{5cm}}{\RaggedRight Countries not experiencing spont. events of disturbance } \\
\midrule
& Obs & Mean & Std Dev. & Obs & Mean & Std. Dev \\
\hline
Urban population (percent) & 525 & 32.527 & 13.186 & 273 & 30.994 & 11.883 \\\hrule
GDP per capita (constant, USD, year 2000) & 462 & 643.516 & 700.011 & 270 & 488.737 & 480.186 \\\hrule
Democracy indicator (Binary) & 474 & 0.409 & 0.492 & 242 & 0.178 & 0.383 \\\hrule
Internet penetration (users/100 of population) & 418 & 2.739 & 4.598 & 213 & 2.916 & 5.954 \\\hrule
Cellphone subscribers (users/100 of population) & 524 & 10.857 & 20.657 & 270 & 12.015 & 24.364 \\
\bottomrule
\end{tabularx}%
\end{document}