3

I am developing some tables on LaTeX environment and I am having some troubles with the spacing. Originally, I was able to generate the tables using the standard \begin{table}, but then I tried to add some features, as the capability to break the table if it is too long (using longtable) the issue appears. I also want to align numbers by decimal point and center, reason why I use siunitx package. The problem is on the last column, which had a width almost the double than the others. If I specify the column width, the problem "disappear", but I'm really interested in the possibility of automatically generate the width of the table.

The code is the following:

\documentclass[paper=a4, fontsize=11pt]{scrartcl}
\usepackage[english]{babel}
\usepackage{siunitx}
\usepackage{longtable}
\usepackage{booktabs}

\begin{document}
\begin{longtable}{l*{4}{S}}
% no problem specifying the column width\begin{longtable}{l*{4}{S[table-column-width=1.25cm]}}
\caption{Univariate Item Descriptives}\\
\toprule
\multicolumn{1}{l}{\textbf{Item}} & \multicolumn{1}{c}{\textbf{Mean}} &    \multicolumn{1}{c}{\textbf{Variance}} & \multicolumn{1}{c}{\textbf{Skewness}} & \multicolumn{1}{c}{\textbf{Kurtosis}} \\
\midrule
\endfirsthead
\multicolumn{5}{c}%
{\tablename\ \thetable\ -- \textit{Univariate Item Descriptives (Continued from previous page)}} \\
\toprule
\textbf{Item} & \textbf{Mean} & \textbf{Variance} & \textbf{Skewness} & \textbf{Kurtosis} \\
\midrule
\endhead
\hline \multicolumn{5}{r}{\textit{Continued on next page}} \\
\endfoot
\bottomrule
\endlastfoot
2. EX +         & 2.788   &    1.060 &        -0.120   &   -0.368\\
3. DS +         & 4.080   &    0.853 &        -1.141   &    1.379\\
4. AM +         & 3.684   &    0.705 &        -0.541   &    0.744\\
5. EX +         & 3.653   &    1.043 &        -0.709   &    0.149\\
6. DS -         & 2.240   &    1.665 &         0.725   &   -0.603\\
7. AM +         & 4.292   &    0.876 &        -1.627   &    2.705\\
8. EX -         & 2.419   &    1.588 &         0.449   &   -0.897\\
9. AM +         & 3.255   &    0.923 &        -0.234   &   -0.037\\
10. DS -        & 3.449   &    1.408 &        -0.453   &   -0.599\\
11. EX +        & 3.678   &    1.232 &        -0.669   &   -0.219\\
12. AM -        & 2.830   &    1.162 &         0.029   &   -0.565\\
13. EX -        & 3.452   &    1.205 &        -0.410   &   -0.336\\
14. DS -        & 2.442   &    1.374 &         0.310   &   -0.893\\
15. AM -        & 2.114   &    1.168 &         0.729   &   -0.176\\
16. EX -        & 3.070   &    1.085 &        -0.176   &   -0.347\\
17. AM +        & 3.893   &    1.116 &        -0.954   &    0.544\\
18. EX +        & 3.311   &    0.964 &        -0.238   &   -0.066\\
19. AM -        & 2.674   &    1.404 &         0.245   &   -0.780\\
\end{longtable}
\end{document}

Output

  • Welcome to TeX.SE! For use S column try to define its format: S[table-format=-1.3]. – Zarko Jul 18 '16 at 8:54
4

The problem is in the continued caption, which is too wide; the excess always goes to the last column.

enter image description here

\documentclass[paper=a4, fontsize=11pt]{scrartcl}
\usepackage[english]{babel}
\usepackage{siunitx}
\usepackage{longtable}
\usepackage{booktabs}

\textheight=8\baselineskip % just for the example

\begin{document}

\begin{longtable}{
  l
  *{2}{S[table-format=1.3]}
  *{2}{S[table-format=-1.3]}
}
\caption{Univariate Item Descriptives}\\
% first head
  \toprule
  \multicolumn{1}{l}{\textbf{Item}} &
  \multicolumn{1}{c}{\textbf{Mean}} &
  \multicolumn{1}{c}{\textbf{Variance}} &
  \multicolumn{1}{c}{\textbf{Skewness}} &
  \multicolumn{1}{c}{\textbf{Kurtosis}} \\
  \midrule
\endfirsthead
% head
  \multicolumn{5}{c}{\tablename\ \thetable\ -- \textit{Univariate Item Descriptives}} \\
  \multicolumn{5}{r}{\textit{Continued from previous page}} \\
  \toprule
  \textbf{Item} & \textbf{Mean} & \textbf{Variance} & \textbf{Skewness} & \textbf{Kurtosis} \\
  \midrule
\endhead
% foot
  \hline \multicolumn{5}{r}{\textit{Continued on next page}} \\
\endfoot
% end foot
\bottomrule
\endlastfoot
% the table
2. EX +         & 2.788   &    1.060 &        -0.120   &   -0.368\\
3. DS +         & 4.080   &    0.853 &        -1.141   &    1.379\\
4. AM +         & 3.684   &    0.705 &        -0.541   &    0.744\\
5. EX +         & 3.653   &    1.043 &        -0.709   &    0.149\\
6. DS -         & 2.240   &    1.665 &         0.725   &   -0.603\\
7. AM +         & 4.292   &    0.876 &        -1.627   &    2.705\\
8. EX -         & 2.419   &    1.588 &         0.449   &   -0.897\\
9. AM +         & 3.255   &    0.923 &        -0.234   &   -0.037\\
10. DS -        & 3.449   &    1.408 &        -0.453   &   -0.599\\
11. EX +        & 3.678   &    1.232 &        -0.669   &   -0.219\\
12. AM -        & 2.830   &    1.162 &         0.029   &   -0.565\\
13. EX -        & 3.452   &    1.205 &        -0.410   &   -0.336\\
14. DS -        & 2.442   &    1.374 &         0.310   &   -0.893\\
15. AM -        & 2.114   &    1.168 &         0.729   &   -0.176\\
16. EX -        & 3.070   &    1.085 &        -0.176   &   -0.347\\
17. AM +        & 3.893   &    1.116 &        -0.954   &    0.544\\
18. EX +        & 3.311   &    0.964 &        -0.238   &   -0.066\\
19. AM -        & 2.674   &    1.404 &         0.245   &   -0.780\\
\end{longtable}
\end{document}

enter image description here

  • I didn't fix the minus signs in the first column, but it should be done – egreg Jul 18 '16 at 9:03
2

If you add

\addtolength\textheight{-30\baselineskip}

You see the cause of the space on page 2

enter image description here

You need to shorten the heading or spread it over two lines so that it does not force the last column to be too wide.

Perhaps

\multicolumn{5}{c}%
{\tablename\ \thetable\ -- \textit{Univariate Item Descriptives}} \\
\multicolumn{5}{r}%
{(\textit{Continued from previous page})} \\
\toprule
\textbf{Item} & \textbf{Mean} & \textbf{Variance} & \textbf{Skewness} & \textbf{Kurtosis} \\
\midrule
\endhead

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.