1

I have a table with some basic descriptive statistics, which I created in RStudio using the stargazer package. This is the code:

\begin{table}[!htbp] \centering 
  \caption{Deskriptive Statistiken und Stichprobenzusammensetzung} 
  \label{} 
\begin{tabular}{@{\extracolsep{5pt}} lccccc} 
\\[-1.8ex]\hline 
\hline \\[-1.8ex] 
 & n & Mittelwert & Standardabweichung & Minimum & Maximum \\ 
\hline \\[-1.8ex] 
Alter & $6,397$ & $38.44$ & $13.06$ & $18$ & $67$ \\ 
Arbeitsweg [in min] & $6,397$ & $26.53$ & $22.73$ & $0$ & $454$ \\ 
Arbeitsweg [in km] & $6,397$ & $15.25$ & $17.03$ & $0$ & $300$ \\ 
subj. Gesundheit & $6,397$ & $3.54$ & $0.93$ & $1$ & $5$ \\ 
Krankheitstage [Vorjahr] & $6,397$ & $16.37$ & $32.41$ & $1$ & $365$ \\ 
wöchentl. Arbeitszeit & $6,397$ & $37.71$ & $10.48$ & $0$ & $95$ \\ 
ISEI-Wert & $6,397$ & $47.17$ & $19.80$ & $11.56$ & $88.70$ \\ 
Frauen & $6,397$ & $0.59$ & $0.49$ & $0$ & $1$ \\ 
\hline \\[-1.8ex] 
\end{tabular} 
\end{table} 

This This the result I get (pls ignore the german labels). It looks good, but as you can see, the table caption is not centered but shifted to the left. How do I change that?

I already tried captionsetup from the caption package, cause thats what a lot of posts suggested:

\documentclass{article}
\usepackage{caption} 
...
\begin{table}[!htbp] \centering 
  \captionsetup {justification = centering}
    \caption{Deskriptive Statistiken und Stichprobenzusammensetzung}

However this didn't work and the caption is still at the same place. In fact, it didn't matter if I used centering, raggedleft, raggedright or any other argument. It didn't move at all. Did I use the package incorrectly? I'm completely new to Latex, so I'm not really sure how stuff works. I'm using overleaf btw, in case it matters

I'm really grateful for any kind of advice. Thanks in advance!

Moritary
  • 11
  • 1
  • 2
    The caption is centred, what is not centred is your table, because it is too wide to fit on your page. – samcarter_is_at_topanswers.xyz Mar 15 '24 at 13:11
  • 1
    Try with & n & $\mu$ & $\sigma$ & Min. & Max. \\ or make a small, but cmopilable test file so we can see what page geometry you have. – samcarter_is_at_topanswers.xyz Mar 15 '24 at 13:13
  • (you might also want to look into the siunitx package to get proper alignment of your figures and spacing around the comma) – samcarter_is_at_topanswers.xyz Mar 15 '24 at 13:13
  • @samcarter_is_at_topanswers.xyz Ah okay! Thanks. But where exactly ido I add the code you posted? In the beginning after \documentclass{} ? (sorry for my stupid questions, I'm a complete noob at this) – Moritary Mar 15 '24 at 13:20
  • 1
    replace your first row & n & Mittelwert & Standardabweichung & Minimum & Maximum \\ with this shorter version. – samcarter_is_at_topanswers.xyz Mar 15 '24 at 13:21
  • Ahhh okay, now I get what you mean! Thank you so much! I deleted the column with n and used \usepackage[a4paper]{geometry} and now it looks good. This way I could keep the original labels, cause they are more precise statistically – Moritary Mar 15 '24 at 14:05
  • Running \usepackage[a4paper]{geometry} actually increases the width (and the height) of the textblock. It's great that you have this degree of freedom in choosing a larger value of the very important parameter \textwidth. It would have been useful if you had mentioned up front that this degree of freedom was available. (It usually isn't...) – Mico Mar 15 '24 at 15:01

1 Answers1

1

In addition to shortening the headers of the five data columns, you should align the numbers on their (implicit or explicit) decimal markers. In the following example, this is done with the help of the S column type of the siunitx package.

enter image description here

A separate comment: Since the sample size of all 8 variables is exactly the same, you could free up a lot of space by deleting the first data column and simply noting somewhere that the sample size is 6,397 in all cases.

\documentclass{article} % or some other suitable document class

\usepackage[ngerman]{babel} \usepackage[T1]{fontenc} \usepackage{siunitx} % for 'S' col. type \newcolumntype{T}[1]{S[table-format=#1]} \usepackage{booktabs} % for well-spaced horizontal rules

\begin{document}

\begin{table}[!htbp] \setlength\tabcolsep{0pt} \sisetup{group-minimum-digits=4,group-separator={,}} \caption{Deskriptive Statistiken und Stichprobenzusammensetzung} \label{tab:Statistiken}

\smallskip \begin{tabular}{\textwidth}{@{\extracolsep{\fill}} l T{4.0} T{2.2} T{2.2} T{2.2} T{3.2} } \toprule & {$n$} & {$\mu$} & {$\sigma$} & {Min.} & {Max.} \ \midrule Alter & 6397 & 38.44 & 13.06 & 18 & 67 \ Arbeitsweg [in min] & 6397 & 26.53 & 22.73 & 0 & 454 \ Arbeitsweg [in km] & 6397 & 15.25 & 17.03 & 0 & 300 \ Subj.\ Gesundheit & 6397 & 3.54 & 0.93 & 1 & 5 \ Krankheitstage [Vorjahr] & 6397 & 16.37 & 32.41 & 1 & 365 \ Wöchentl.\ Arbeitszeit & 6397 & 37.71 & 10.48 & 0 & 95 \ ISEI-Wert & 6397 & 47.17 & 19.80 & 11.56 & 88.70 \ Frauen & 6397 & 0.59 & 0.49 & 0 & 1 \ \bottomrule \end{tabular} \end{table}

\end{document}

Mico
  • 506,678