LaTeX forum ⇒ Graphics, Figures & TablesEntries of large Table not aligned with Columns Topic is solved

Information and discussion about graphics, figures & tables in LaTeX documents.
NELLLY
Posts: 113
Joined: Thu Nov 26, 2009 2:21 am

Entries of large Table not aligned with Columns

Postby NELLLY » Sat Apr 27, 2013 12:09 am

Hi,

I have a large table, previously I posted on the forum about how to get a large table such that it doesn't exceed the width of the page. Inspired from the answer I used the following instructions.
  1. \documentclass{article}
  2. \usepackage{booktabs}
  3. \usepackage{array}
  4. \usepackage{siunitx}
  5. \usepackage{lipsum} % dummy text
  6.  
  7. \begin{document}
  8. \lipsum[1]
  9.  
  10. \begin{table}[ht]
  11. \makebox[\textwidth][c]{\footnotesize
  12. \begin{tabular}{@{}>{$}r<{$}@{}*{14}{S[table-format=-3]}@{}}
  13. \toprule
  14. &\multicolumn{6}{c}{Optimal design parameters}
  15. &\multicolumn{6}{c}{Statistical performance}\\
  16. \cmidrule(lr){2-7}\cmidrule(lr){8-13}
  17. Run&{$n$}&{$WL$}&{$UCL$}&{$h_1$}&{$h_2$}&{$ETCU_s^*$}
  18. &{$ANSSC$}&{$ANOC$}&{$ANFA$}&{$ANSS$}&{$ANOS$}&{$ATS$}
  19. &{$\triangle C_{Fp}$}&{$\triangle C_{VSS}$}\\
  20. \midrule
  21. $1$ &14&0&2&5.58&0.01&1.49&275.01&3850.18&2.11&3.21&44.50&4.98&13.87\%&3.25\%\\\bottomrule[1.2pt]
  22. \end{tabular}
  23. }
  24. \caption{Caption}
  25. \end{table}
  26. \end{document}

In the output, the numbers are not aligned with the column labels. What should I do?

Tags:

User avatar
localghost
Site Moderator
Posts: 9204
Joined: Fri Feb 02, 2007 12:06 pm

Postby localghost » Sat Apr 27, 2013 10:40 am

You have to give the digits format explicitly for every S column type. These specifications are based on the table row you posted and might need to be corrected if digits with other formats occur later in a column.
  1. \documentclass[11pt]{article}
  2. \usepackage[T1]{fontenc}
  3. \usepackage{caption}
  4. \usepackage{array,booktabs,multirow}
  5. \usepackage{mathtools}
  6. \usepackage{siunitx}
  7. \usepackage{lipsum} % dummy text
  8.  
  9. \begin{document}
  10. \lipsum[1]
  11.  
  12. \begin{table}[ht]
  13. \caption{Caption}
  14. \label{tab:dummy}
  15. \makebox[\textwidth][c]{%
  16. \footnotesize%
  17. \begin{tabular}{
  18. r
  19. S[table-format=2.0]
  20. S[table-format=1.0]
  21. S[table-format=1.0]
  22. S[table-format=1.2]
  23. S[table-format=1.2]
  24. S[table-format=1.2]
  25. S[table-format=3.2]
  26. S[table-format=4.2]
  27. S[table-format=1.2]
  28. S[table-format=1.2]
  29. S[table-format=2.2]
  30. S[table-format=1.2]
  31. S[table-format=2.2]
  32. S[table-format=1.2]
  33. }\toprule
  34. \multirow{2}{*}[-0.75ex]{Run} & \multicolumn{6}{c}{Optimal design parameters} & \multicolumn{6}{c}{Statistical performance} & {$\Delta C_\text{Fp}$} & {$\Delta C_\text{VSS}$} \\ \cmidrule(lr){2-7}\cmidrule(lr){8-13}
  35. & {$n$} & {WL} & {UCL} & {$h_1$} & {$h_2$} & {$\text{ETCU}_s^*$} & {ANSSC} & {ANOC} & {ANFA} & {ANSS} & {ANOS} & {ATS} & {(\%)} & {(\%)} \\ \midrule
  36. 1 & 14 & 0 & 2 & 5.58 & 0.01 & 1.49 & 275.01 & 3850.18 & 2.11 & 3.21 & 44.50 & 4.98 & 13.87 & 3.25 \\ \bottomrule
  37. \end{tabular}%
  38. }
  39. \end{table}
  40. \end{document}



Remarks:

  • Tables have their captions above.


Thorsten
LaTeX Community Moderator
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes


¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1

NELLLY
Posts: 113
Joined: Thu Nov 26, 2009 2:21 am

Postby NELLLY » Sat Apr 27, 2013 4:12 pm

Many thanks Localghost. Your solution works perfectly.I adopted it also for my second table but this time it exceeds a little bit the width of the page
  1. \documentclass[11pt]{article}
  2. \usepackage[T1]{fontenc}
  3. \usepackage{caption}
  4. \usepackage{array,booktabs,multirow}
  5. \usepackage{mathtools}
  6. \usepackage{siunitx}
  7. \usepackage{lipsum} % dummy text
  8.  
  9. \begin{document}
  10. \lipsum[1]
  11. \begin{table}[ht]
  12. \caption{Name}
  13. \label{tab:dumm3}
  14. \makebox[\textwidth][c]{%
  15. \footnotesize%
  16. \begin{tabular}{
  17. c
  18. S[table-format=2.0]
  19. S[table-format=2.0]
  20. S[table-format=1.0]
  21. S[table-format=1.0]
  22. S[table-format=1.0]
  23. S[table-format=1.2]
  24. S[table-format=3.2]
  25. S[table-format=4.2]
  26. S[table-format=1.2]
  27. S[table-format=1.2]
  28. S[table-format=2.2]
  29. S[table-format=1.2]
  30. S[table-format=2.2]
  31. S[table-format=1.2]
  32. S[table-format=1.2]
  33. }\toprule
  34.  
  35. \multirow{2}{*}[-0.75ex]{Run}& \multicolumn{9}{c}{Optimal design parameters} & \multicolumn{6}{c}{Statistical performance} \\ \cmidrule(lr){2-10}\cmidrule(lr){11-16}
  36.  
  37.  
  38. &{$n_1$}&{$n_2$}&{$UWL_1$}&{$UCL_1$}&{$UWL_2$}&{$UCL_2$}&{$h$}&{$ETCU_s^*$}& {$\Delta C_\text{Fp}$(\%)}&{$ANSSC$}&{$ANOC$}&{$ANFA$}&{$ANSS$}&{$ANOS$}&{$ATS$}\\
  39. \midrule
  40. 1&2&24&0&1&0.51&3.98&0.99&1.54&10.98&1009.60&4483.95&1.40&5.75&58.08&5.20\\
  41. 2&4&13&0&1&0.17&1.98&1.74&5.64&3.42&191.07&1024.39&2.41&3.69&27.21&5.55\\
  42. $3$&51&77&3&5&4.12&6.57&5.22&4.35&0.68&63.36&3366.84&0.28&1.28&73.06&4.08\\
  43. $4$&3&20&0&1&0.37&2.95&3.76&3.28&3.24&265.46&1443.87&1.38&4.15&39.38&13.73\\
  44. $5$&12&16&0&1&0.06&1.22&6.12&5.01&0.59&53.97&722.26&3.22&1.50&20.77&6.11\\
  45. $6$&33&51&2&3&2.79&4.03&7.9&1.94&0.51&126.08&4374.62&2.11&1.22&44.29&5.68\\
  46. $7$&2&14&0&1&0.26&2.91&1.69&2.74&14.64&591.22&1786.80&0.86&6.08&39.73&9.44\\
  47. $8$&1&20&0&1&0.47&4.94&0.25&3.46&13.5&1332.83&2688.19&0.02&11.70&103.97&2.80\\
  48. $9$&13&16&0&1&0.08&1.19&11.4&3.40&0.29&87.22&1272.78&14.28&1.59&23.46&12.40\\
  49. $10$&49&68&3&5&4.05&6.40&5.95&4.61&0.43&55.52&2982.56&2.16&1.32&73.97&4.88\\
  50. $11$&2&30&0&1&1.11&4.99&1.65&6.77&8.51&201.52&1284.36&0.90&6.03&74.84&9.13\\
  51. $12$&1&48&0&1&2.05&8.98&0.60&2.26&14.07&1666.17&8081.64&0.07&11.94&223.15&6.87\\
  52. $13$&2&28&0&1&1.02&4.77&0.68&3.75&8.09&489.70&2821.91&1.87&5.17&60.88&3.17\\
  53. $14$&3&9&0&1&1.90&1.92&2.69&2.85&3.06&489.70&2821.91&1.87&5.17&60.88&3.17\\
  54. $15$&66&111&6&8&9.05&11.64&11.08&2.18&0.91&89.75&6154.86&0.51&1.27&94.65&8.53\\
  55. $16$&2&29&0&1&1.07&4.87&1.83&7.43&2.36&181.65&1113.08&0.75&4.96&59.12&8.16\\\bottomrule
  56. \end{tabular}
  57. }
  58. \end{table}
  59. \end{document}

What should I add? Also I need the values to be centered. Thanks

User avatar
localghost
Site Moderator
Posts: 9204
Joined: Fri Feb 02, 2007 12:06 pm

Postby localghost » Sun Apr 28, 2013 10:01 am

NELLLY wrote:[…] I adopted it also for my second table but this time it exceeds a little bit the width of the page. […]

It's not the table that exceeds the page, it's the content of certain cells that causes the warnings. You didn't work thoroughly when adjusting table-format for the S columns.
  1. \documentclass[11pt]{article}
  2. \usepackage[T1]{fontenc}
  3. \usepackage{caption}
  4. \usepackage{array,booktabs,multirow}
  5. \usepackage{mathtools}
  6. \usepackage{siunitx}
  7. \usepackage{lipsum} % dummy text
  8.  
  9. \begin{document}
  10. \lipsum[1]
  11. \begin{table}[!ht]
  12. \caption{Table caption}
  13. \label{tab:dummy}
  14. \makebox[\textwidth][c]{%
  15. \footnotesize%
  16. \begin{tabular}{
  17. S[table-format=2.0]
  18. S[table-format=2.0]
  19. S[table-format=3.0]
  20. S[table-format=1.0]
  21. S[table-format=1.0]
  22. S[table-format=1.2]
  23. S[table-format=2.2]
  24. S[table-format=2.2]
  25. S[table-format=1.2]
  26. S[table-format=2.2]
  27. S[table-format=4.2]
  28. S[table-format=4.2]
  29. S[table-format=2.2]
  30. S[table-format=2.2]
  31. S[table-format=3.2]
  32. S[table-format=2.2]
  33. }\toprule
  34. {\multirow{2}{*}[-0.75ex]{Run}} & \multicolumn{9}{c}{Optimal design parameters} & \multicolumn{6}{c}{Statistical performance} \\ \cmidrule(lr){2-10}\cmidrule(lr){11-16}
  35. & {$n_1$} & {$n_2$} & {$\text{UWL}_1$} & {$\text{UCL}_1$} & {$\text{UWL}_2$} & {$\text{UCL}_2$} & {$h$} & {$\text{ETCU}_s^*$} & {$\Delta C_\text{Fp}$(\%)} & {ANSSC} & {ANOC} & {ANFA} & {ANSS} & {ANOS} & {ATS} \\ \midrule
  36. 1 & 2 & 24 & 0 & 1 & 0.51 & 3.98 & 0.99 & 1.54 & 10.98 & 1009.60 & 4483.95 & 1.40 & 5.75 & 58.08 & 5.20 \\
  37. 2 & 4 & 13 & 0 & 1 & 0.17 & 1.98 & 1.74 & 5.64 & 3.42 & 191.07 & 1024.39 & 2.41 & 3.69 & 27.21 & 5.55 \\
  38. 3 & 51 & 77 & 3 & 5 & 4.12 & 6.57 & 5.22 & 4.35 & 0.68 & 63.36 & 3366.84 & 0.28 & 1.28 & 73.06 & 4.08 \\
  39. 4 & 3 & 20 & 0 & 1 & 0.37 & 2.95 & 3.76 & 3.28 & 3.24 & 265.46 & 1443.87 & 1.38 & 4.15 & 39.38 & 13.73 \\
  40. 5 & 12 & 16 & 0 & 1 & 0.06 & 1.22 & 6.12 & 5.01 & 0.59 & 53.97 & 722.26 & 3.22 & 1.50 & 20.77 & 6.11 \\
  41. 6 & 33 & 51 & 2 & 3 & 2.79 & 4.03 & 7.9 & 1.94 & 0.51 & 126.08 & 4374.62 & 2.11 & 1.22 & 44.29 & 5.68 \\
  42. 7 & 2 & 14 & 0 & 1 & 0.26 & 2.91 & 1.69 & 2.74 & 14.64 & 591.22 & 1786.80 & 0.86 & 6.08 & 39.73 & 9.44 \\
  43. 8 & 1 & 20 & 0 & 1 & 0.47 & 4.94 & 0.25 & 3.46 & 13.5 & 1332.83 & 2688.19 & 0.02 & 11.70 & 103.97 & 2.80 \\
  44. 9 & 13 & 16 & 0 & 1 & 0.08 & 1.19 & 11.4 & 3.40 & 0.29 & 87.22 & 1272.78 & 14.28 & 1.59 & 23.46 & 12.40 \\
  45. 10 & 49 & 68 & 3 & 5 & 4.05 & 6.40 & 5.95 & 4.61 & 0.43 & 55.52 & 2982.56 & 2.16 & 1.32 & 73.97 & 4.88 \\
  46. 11 & 2 & 30 & 0 & 1 & 1.11 & 4.99 & 1.65 & 6.77 & 8.51 & 201.52 & 1284.36 & 0.90 & 6.03 & 74.84 & 9.13 \\
  47. 12 & 1 & 48 & 0 & 1 & 2.05 & 8.98 & 0.60 & 2.26 & 14.07 & 1666.17 & 8081.64 & 0.07 & 11.94 & 223.15 & 6.87 \\
  48. 13 & 2 & 28 & 0 & 1 & 1.02 & 4.77 & 0.68 & 3.75 & 8.09 & 489.70 & 2821.91 & 1.87 & 5.17 & 60.88 & 3.17 \\
  49. 14 & 3 & 9 & 0 & 1 & 1.90 & 1.92 & 2.69 & 2.85 & 3.06 & 489.70 & 2821.91 & 1.87 & 5.17 & 60.88 & 3.17 \\
  50. 15 & 66 & 111 & 6 & 8 & 9.05 & 11.64 & 11.08 & 2.18 & 0.91 & 89.75 & 6154.86 & 0.51 & 1.27 & 94.65 & 8.53 \\
  51. 16 & 2 & 29 & 0 & 1 & 1.07 & 4.87 & 1.83 & 7.43 & 2.36 & 181.65 & 1113.08 & 0.75 & 4.96 & 59.12 & 8.16 \\ \bottomrule
  52. \end{tabular}
  53. }
  54. \end{table}
  55. \end{document}



Remarks:

  • It can't do any harm to format already the source accordingly in order to stay on top of things (see code). (La)TeX doesn't care about the format of the source. But it helps you for better readability.
  • It seems better to rotate such tables by the rotating package and place them on their own page by the sidewaystable environment.
LaTeX Community Moderator
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes


¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1

NELLLY
Posts: 113
Joined: Thu Nov 26, 2009 2:21 am

Postby NELLLY » Tue Apr 30, 2013 10:17 pm

Many thanks, it works perfectly now.


Return to “Graphics, Figures & Tables”

Who is online

Users browsing this forum: No registered users and 6 guests