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). Does anyone know how to do it? enter image description here

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]}}
 &         {N}&      {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}
3
  • 1
    What is the s second column type, as opposed to S?
    – Bernard
    Jun 5, 2020 at 8:16
  • I don't quite know. But without the small "s" it does not put the thousand's comma separator. The problem is also at the big "S" columns.
    – Morzen
    Jun 5, 2020 at 8:25
  • To get proper thousands-separators (with commas functioning as the separators), do by all means use the S column type. Just set the options group-separator={,} and group-minimum-digits=4, and make sure to delete the commas in the input numbers.
    – Mico
    Jun 8, 2020 at 19:39

1 Answer 1

1

Here is a solution, if I've well understood, with some æsthetic suggestions:

\documentclass[12pt,a4paper]{article}
\usepackage{siunitx}
\usepackage{caption}
\captionsetup{skip=6pt, labelfont=sc, textfont=it}
\usepackage{calc}
\newcommand\myShead[1]{\multicolumn{1}{c}{\parbox{\widthof{0.500}}{#1}}}

\begin{document}

\begin{table}[htbp]\centering
\sisetup{table-format = 1.3, table-number-alignment=center, group-separator={,}}
\caption{Descriptive Statistics}
\begin{tabular}{l!{\vrule width1pt}S[table-format =5.0]*{2}{|S}|S[table-format =-1.2]|S}
 & \multicolumn{1}{l}{N}& \myShead{Mean}& \myShead{S.D} & \myShead{\phantom{$-\!$}Min}& \myShead{Max}\\
A& 95703 & 0.522& 0.500& 0& 1\\
B& 94826& 0.062& 0.241& 0& 1\\
C& 94301& 3.080& 1.435& 1& 6\\
D& 90049& 0.332& 0.471& 0& 1\\
E& 94860& 0.065& 0.960& -5.27& 3.49\\
\end{tabular}
\end{table}

\end{document} 

enter image description here

1
  • Awesome. Thanks
    – Morzen
    Jun 5, 2020 at 9:51

You must log in to answer this question.

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