1

I am trying to produce a table with the Siunitx package, and to make the text in the header to be left aligned and to start where the numbers begin (see the red line in the attached screenshot). enter image description here I got an answer for a similar question (see Original question), but in the original question the column name was short.

MWE:

%:Class
\documentclass[12pt,a4paper]{article}
\usepackage{siunitx}
%:begin
\begin{document}
\begin{table}[htbp]\centering
\caption{Descriptive Statistics}
\begin{tabular}{l|s[table-text-alignment = left]*{4}{|S[table-number-alignment = left]}}
 &         {Observations}&      {Mean}&      {S.D.}&       {Min}&       {Max}\\
A&      95,703&       0.522&       0.500&           0&           1\\
B&      94,826&       0.062&       0.241&           0&           1\\
C&      94,301&       3.080&       1.435&           1&           6\\
D&      90,049&       0.332&       0.471&           0&           1\\
E&      94,860&       0.065&       0.960&       -5.27&        3.49\\
\end{tabular}
\end{table}
\end{document}
5
  • 1
    What do the commas in the first data column denote? Thousands-separators? Something else?
    – Mico
    Jun 8, 2020 at 18:24
  • Separately, what's the reason for using the s column type for the first data column. Should this maybe be S?
    – Mico
    Jun 8, 2020 at 18:35
  • @Mico: In the comments to one of their previous questions, OP commented on their use of s instead of S: tex.stackexchange.com/questions/547907/…
    – leandriis
    Jun 8, 2020 at 19:08
  • 1
    @leandriis - Thanks for this link. I've left a comment below the linked comment, pointing out that it is not necessary or, frankly, even advisable to use the s column type in this way. Instead, the OP should do what you did in your answer shown below: employ the S column type, either set the option input-ignore={,} or just delete the commas in the affected cells, and set the option group-minimum-digits=4 if need be.
    – Mico
    Jun 8, 2020 at 19:42
  • Indeed, the s column was left in the MWE by mistake. The commas in the first data column are also redundant.
    – Morzen
    Jun 9, 2020 at 3:55

1 Answer 1

2

With the appropriate siunitx options and under the assumption that the , in the first column are thousands-separators:

enter image description here

\documentclass[12pt,a4paper]{article}
\usepackage{siunitx}
%:begin
\begin{document}
\begin{table}[htbp]\centering
\sisetup{input-ignore={,}, 
         input-decimal-markers = {.}, 
         group-separator={,}, 
         table-text-alignment = left}
\caption{Descriptive Statistics}
\begin{tabular}{l|S*{2}{|S[table-format=1.3]}|S[table-format=-1.2]|S[table-format=1.2]}
 & {Observations}&      {Mean} &      {S.D.} &       {Min} &       {Max} \\
A&      95,703   &       0.522 &       0.500 &           0 &           1 \\
B&      94,826   &       0.062 &       0.241 &           0 &           1 \\
C&      94,301   &       3.080 &       1.435 &           1 &           6 \\
D&      90,049   &       0.332 &       0.471 &           0 &           1 \\
E&      94,860   &       0.065 &       0.960 &       -5.27 &        3.49 \\
\end{tabular}
\end{table}
\end{document}
2
  • 2
    +1. I might also abbreviate Observations to Obs. :-)
    – Mico
    Jun 8, 2020 at 18:33
  • @leandriis Could you the same thing if all column names were long? for example if all column names were "Observations"?
    – Morzen
    Jun 9, 2020 at 8:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .