0

I am struggling with an issue regarding numbers alignment in a table. I have the following example (notice that I am using the style provided by the journal, which can be downloaded from here):

\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}

The result is attached here: enter image description here

The numbers are not aligned. I would like to have them aligned according to the decimals.

So I use the following code:

\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}

The result is:

enter image description here

However, everything is messy. Numbers are now aligned, but they are not aligned with the corresponding text. Only the Observations column looks fine, while for the others even the font has been changed. I cannot understand why. Any suggestion? Thanks in advance.

0

Note you could have made an example just using article class and dcolumn package.

You have specified 3.3 for the columns so for example your S.D heading is centred over a column of numbers allowing for 002.250 If you want to centre over the numbers that you show, that column should be d{1.2} and similarly adjust the other columns. Note you should also use d{7.0} not c for the obs column so that they are aligned rather than centred (which looks the same as they all have the same length) and use the math font like the other columns.

  • Thanks for the suggestion David. You are right. I could use article and dcolumn. But If I use article, then I cannot show what happens to the font. I would like to have the font as for the column Obs. Instead when I use dcolumn, i get another font from numbers from Mean column on. You suggest to use the math font like the other columns, But I did not get this point. I am not using math font at all. – Dario Oct 18 '18 at 15:19
  • you could just have put \sffamily before the table, the text columns are using a sans serif font but dcolumn makes math mode columns (which is usually best for numbers, especially if they may be negative) – David Carlisle Oct 18 '18 at 15:38
  • @Dario you are using math in all the dcolumn columns, it is a math mode construct. If your numbers are all pre-formated to the same number of decimal places, and you want text mode, just use r columns. (But then you need a text mode minus sign) – David Carlisle Oct 18 '18 at 15:39
  • Hi David, I tried to put \sffamily before the table. I guess I should enter something like this (in order to create a new column type?): \makeatletter \newcolumntype{T}[3]{>{\sffamily\the\font\DC@{#1}{#2}{#3}}c<{\DC@end}} \makeatother. I am not sure if this is right. For sure it does not work. The only way I managed to make changes is to write \sffamily{125,902} for instance. But it is really annoying to change each number in the table, also because I have other tables with a lot of entries. Any suggestion? – Dario Oct 18 '18 at 18:24
  • @Dario I meant you could make an example showing different text and math fonts without using lotd of packages just by putting \sffamily before the tabular that would make the first two columms sans serif. \sffamily has no effect on d, column tables as they are math mode. As I said above, you could use text mode columns and use r not d{3.3} – David Carlisle Oct 18 '18 at 18:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.