使用 dcolumn 对齐表格

使用 dcolumn 对齐表格

我正在努力解决表格中数字对齐的问题。我有以下示例(请注意,我使用的是期刊提供的样式,可从以下网址下载这里):

\documentclass[biblatex]{apsr_submission}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{graphicx}
\usepackage{wrapfig}
\usepackage{lscape}
\usepackage[counterclockwise]{rotating}
\usepackage{bm}
\usepackage{multirow}
\usepackage{longtable}
\usepackage{booktabs}
\usepackage{epstopdf}
\usepackage{pdflscape}

\usepackage{dcolumn,booktabs}

\newcommand\mc[1]{\multicolumn{1}{c}{#1}}

\begin{document}

\begin{table}[hbt!]
\setlength{\tabcolsep}{7pt}
\caption{Summary statistics}
\label{tab:sumstat}
\centering
\begin{tabular}{lccccc }
Variables &\mc{Obs.} &\mc{Mean} &\mc{S.D.}&\mc{Min.} & \mc{Max.} \\ \midrule
HP        &125,902   &0.83      &0.38     &0     &1\\ 
CAF       &125,902   &-0.16     &2.25     &-8    &5\\
GLOB      &125,902   &0.28      & 0.45    &0     &1
\end{tabular}
\floatnote{The Table reports the summary statistics of the main variables used in the analysis. HP is a dummy variable taking the value of 1 if the individual declares to be "very" or "quite" happy and 0 otherwise. CAF indicates the extent of autonomy freedom enjoyed by the individuals in our sample, centered around the median value of the countries where each of them live. GLOB is a dummy variable taking the value of 1 if a country enjoys a large extent of globalization and 0 otherwise and it is based on the KOF index (Dreher, 2006). A full description of those data, along with the others used in the analysis is reported in the Appendix.}
\end{table}

\end{document}

结果附于此处: 在此处输入图片描述

数字没有对齐。我想让它们按照小数位对齐。

因此我使用以下代码:

\documentclass[biblatex]{apsr_submission}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{graphicx}
\usepackage{wrapfig}
\usepackage{lscape}
\usepackage[counterclockwise]{rotating}
\usepackage{bm}
\usepackage{multirow}
\usepackage{longtable}
\usepackage{booktabs}
\usepackage{epstopdf}
\usepackage{pdflscape}

\usepackage{dcolumn,booktabs}
\newcolumntype{d}[1]{D{.}{.}{#1}}
\newcommand\mc[1]{\multicolumn{1}{c}{#1}}

\begin{document}

\begin{table}[hbt!]
\setlength{\tabcolsep}{7pt}
\caption{Summary statistics}
\label{tab:sumstat}
\centering
\begin{tabular}{l c*{5}{d{3.3}} }
Variables   &\mc{Obs.} &\mc{Mean}  &\mc{S.D.} &\mc{Min.} &\mc{Max.} \\ \midrule
HP           &125,902   &0.83       &0.38     &0     &1\\ 
CAF          &125,902   &-0.16      & 2.25    &-8    &5\\
GLOB         &125,902   &0.28       & 0.45    &0     &1
\end{tabular}
\floatnote{The Table reports the summary statistics of the main variables used in the analysis. HP is a dummy variable taking the value of 1 if the individual declares to be "very" or "quite" happy and 0 otherwise. CAF indicates the extent of autonomy freedom enjoyed by the individuals in our sample, centered around the median value of the countries where each of them live. GLOB is a dummy variable taking the value of 1 if a country enjoys a large extent of globalization and 0 otherwise and it is based on the KOF index (Dreher, 2006). A full description of those data, along with the others used in the analysis is reported in the Appendix.}
\end{table}

结果是:

在此处输入图片描述

但是,一切都乱糟糟的。数字现在对齐了,但它们没有与相应的文本对齐。只有“观察”列看起来正常,而其他列的字体甚至都变了。我不明白为什么。有什么建议吗?提前谢谢。

答案1

请注意,您可以仅使用article类和dcolumn包来创建一个示例。

您已指定了3.3列,例如,您的 SD 标题位于数字列的中央,以便002.250 如果您想将显示的数字居中,则该列应该是,d{1.2}并同样调整其他列。请注意,您还应该对 obs 列使用d{7.0}not c,以便它们对齐而不是居中(看起来一样,因为它们的长度都相同),并使用与其他列相同的数学字体。

相关内容