LaTeX forum ⇒ Graphics, Figures & TablesProblem with large table in landscape mode Topic is solved

Information and discussion about graphics, figures & tables in LaTeX documents.
User avatar
Cham
Posts: 819
Joined: Sat Apr 02, 2011 4:06 pm

Problem with large table in landscape mode

Postby Cham » Thu Nov 09, 2017 7:07 pm

I have a large table (30 columns !) that I don't want to split into parts. I should have a proper space in landscape mode, but I still have difficulties in setting the table which have problems on its right side.

The table should take all the space available on the text page, and the font size should be as large as possible. Here's a MWE showing the problem. Any help would be greatly appreciated !

  1. \documentclass[11pt,oneside]{article}
  2. \usepackage[T1]{fontenc}
  3. \usepackage{microtype}
  4. \usepackage[left=0.75in,right=0.75in,top=0.5in,bottom=0.5in,includehead,includefoot]{geometry}
  5. \usepackage{tabularx}
  6. \usepackage{hhline}
  7. \usepackage{here}
  8. \usepackage{pdflscape}
  9.  
  10. \begin{document}
  11.  
  12. \begin{landscape}
  13. \begin{center}
  14. \Large\textbf{Some extremely boring title}
  15. \end{center}
  16.  
  17. \bigskip
  18.  
  19. \tabcolsep=0.15cm
  20. \begin{table}[H]
  21. \tiny % A bit too small. Could be larger.
  22. \centering
  23. \renewcommand{\arraystretch}{2}
  24. \begin{tabularx}{\textwidth}{|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|}
  25. \hline
  26. \multicolumn{30}{|c|}{Some funny title}
  27. \\ \hline
  28. \multicolumn{1}{|>{\centering\arraybackslash}X|}{$t$}
  29. & \multicolumn{1}{>{\centering\arraybackslash}X|}{$N_{1}$}
  30. & \multicolumn{1}{>{\centering\arraybackslash}X|}{$N_{2}$}
  31. & \multicolumn{1}{>{\centering\arraybackslash}X|}{$N_{3}$}
  32. & \multicolumn{1}{>{\centering\arraybackslash}X|}{$N_{4}$}
  33. & \multicolumn{1}{>{\centering\arraybackslash}X|}{$N_{5}$}
  34. & \multicolumn{1}{>{\centering\arraybackslash}X|}{$N_{6}$}
  35. & \multicolumn{1}{>{\centering\arraybackslash}X|}{$N_{7}$}
  36. & \multicolumn{1}{>{\centering\arraybackslash}X|}{$N_{8}$}
  37. & \multicolumn{1}{>{\centering\arraybackslash}X|}{$N_{9}$}
  38. & \multicolumn{1}{>{\centering\arraybackslash}X|}{$N_{10}$}
  39. & \multicolumn{1}{>{\centering\arraybackslash}X|}{$N_{11}$}
  40. & \multicolumn{1}{>{\centering\arraybackslash}X|}{$N_{12}$}
  41. & \multicolumn{1}{>{\centering\arraybackslash}X|}{$N_{13}$}
  42. & \multicolumn{1}{>{\centering\arraybackslash}X|}{$N_{14}$}
  43. & \multicolumn{1}{>{\centering\arraybackslash}X|}{$N_{15}$}
  44. & \multicolumn{1}{>{\centering\arraybackslash}X|}{$N_{16}$}
  45. & \multicolumn{1}{>{\centering\arraybackslash}X|}{$N_{17}$}
  46. & \multicolumn{1}{>{\centering\arraybackslash}X|}{$N_{18}$}
  47. & \multicolumn{1}{>{\centering\arraybackslash}X|}{$N_{19}$}
  48. & \multicolumn{1}{>{\centering\arraybackslash}X|}{$N_{20}$}
  49. & \multicolumn{1}{>{\centering\arraybackslash}X|}{$N_{21}$}
  50. & \multicolumn{1}{>{\centering\arraybackslash}X|}{$N_{22}$}
  51. & \multicolumn{1}{>{\centering\arraybackslash}X|}{$N_{23}$}
  52. & \multicolumn{1}{>{\centering\arraybackslash}X|}{$N_{24}$}
  53. & \multicolumn{1}{>{\centering\arraybackslash}X|}{$N_{25}$}
  54. & \multicolumn{1}{>{\centering\arraybackslash}X|}{$N_{26}$}
  55. & \multicolumn{1}{>{\centering\arraybackslash}X|}{$N_{27}$}
  56. & \multicolumn{1}{>{\centering\arraybackslash}X|}{$N_{28}$}
  57. & \multicolumn{1}{>{\centering\arraybackslash}X|}{$N_{29}$}
  58. \\ \hline
  59. \multicolumn{1}{|c|}{$L$}
  60. & \multicolumn{29}{c|}{some hilarious unit}
  61. \\ \hhline{|=|=|=|=|=|=|=|=|=|=|=|=|=|=|=|=|=|=|=|=|=|=|=|=|=|=|=|=|=|=|}
  62. 0 & 300 & 300 & 300 & 300 & 300 & 300 & 300 & 300 & 300 & 300 & 300 & 300 & 300 & 300 & 300 & 300 & 300 & 300 & 300 & 300 & 300 & 300 & 300 & 300 & 300 & 300 & 300 & 300 & 300
  63. \\ \hline
  64. 1 & 281 & 282 & 283 & 285 & 283 & 282 & 283 & 283 & 277 & 285 & 279 & 282 & 285 & 279 & 284 & 278 & 284 & 276 & 281 & 286 & 279 & 290 & 277 & 284 & 290 & 282 & 290 & 286 & 281
  65. \\ \hline
  66. \end{tabularx}
  67. \caption{Some very funny caption. LOL !}
  68. \end{table}
  69. \end{landscape}
  70.  
  71. \end{document}


Here's a preview of the table and its problem :
funnytable.jpg
funnytable.jpg (24.72 KiB) Viewed 179 times

User avatar
Cham
Posts: 819
Joined: Sat Apr 02, 2011 4:06 pm

Postby Cham » Fri Nov 10, 2017 1:28 am

I think I've found a solution : the adjustbox package :

  1. \documentclass[11pt,oneside]{article}
  2. \usepackage[T1]{fontenc}
  3. \usepackage{microtype}
  4. \usepackage[left=0.75in,right=0.75in,top=0.5in,bottom=0.5in,includehead,includefoot]{geometry}
  5. \usepackage{tabularx}
  6. \usepackage{hhline}
  7. \usepackage{here}
  8. \usepackage{pdflscape}
  9. \usepackage{adjustbox}
  10.  
  11. \begin{document}
  12.  
  13. \begin{landscape}
  14. \begin{center}
  15. \Large\textbf{Some extremely boring title}
  16. \end{center}
  17.  
  18. \bigskip
  19.  
  20. \tabcolsep=0.15cm
  21. \begin{table}[H]
  22. \centering
  23. \tabcolsep=0.15cm
  24. \renewcommand{\arraystretch}{1.5}
  25. \begin{adjustbox}{max width=\linewidth}
  26. \begin{tabular}{|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|}
  27. \hline
  28. \multicolumn{30}{|c|}{Some hilarious title}
  29. \\ \hline
  30. \multicolumn{1}{|>{\centering\arraybackslash}c|}{$t$}
  31. & \multicolumn{1}{>{\centering\arraybackslash}c|}{$N_{1}$}
  32. & \multicolumn{1}{>{\centering\arraybackslash}c|}{$N_{2}$}
  33. & \multicolumn{1}{>{\centering\arraybackslash}c|}{$N_{3}$}
  34. & \multicolumn{1}{>{\centering\arraybackslash}c|}{$N_{4}$}
  35. & \multicolumn{1}{>{\centering\arraybackslash}c|}{$N_{5}$}
  36. & \multicolumn{1}{>{\centering\arraybackslash}c|}{$N_{6}$}
  37. & \multicolumn{1}{>{\centering\arraybackslash}c|}{$N_{7}$}
  38. & \multicolumn{1}{>{\centering\arraybackslash}c|}{$N_{8}$}
  39. & \multicolumn{1}{>{\centering\arraybackslash}c|}{$N_{9}$}
  40. & \multicolumn{1}{>{\centering\arraybackslash}c|}{$N_{10}$}
  41. & \multicolumn{1}{>{\centering\arraybackslash}c|}{$N_{11}$}
  42. & \multicolumn{1}{>{\centering\arraybackslash}c|}{$N_{12}$}
  43. & \multicolumn{1}{>{\centering\arraybackslash}c|}{$N_{13}$}
  44. & \multicolumn{1}{>{\centering\arraybackslash}c|}{$N_{14}$}
  45. & \multicolumn{1}{>{\centering\arraybackslash}c|}{$N_{15}$}
  46. & \multicolumn{1}{>{\centering\arraybackslash}c|}{$N_{16}$}
  47. & \multicolumn{1}{>{\centering\arraybackslash}c|}{$N_{17}$}
  48. & \multicolumn{1}{>{\centering\arraybackslash}c|}{$N_{18}$}
  49. & \multicolumn{1}{>{\centering\arraybackslash}c|}{$N_{19}$}
  50. & \multicolumn{1}{>{\centering\arraybackslash}c|}{$N_{20}$}
  51. & \multicolumn{1}{>{\centering\arraybackslash}c|}{$N_{21}$}
  52. & \multicolumn{1}{>{\centering\arraybackslash}c|}{$N_{22}$}
  53. & \multicolumn{1}{>{\centering\arraybackslash}c|}{$N_{23}$}
  54. & \multicolumn{1}{>{\centering\arraybackslash}c|}{$N_{24}$}
  55. & \multicolumn{1}{>{\centering\arraybackslash}c|}{$N_{25}$}
  56. & \multicolumn{1}{>{\centering\arraybackslash}c|}{$N_{26}$}
  57. & \multicolumn{1}{>{\centering\arraybackslash}c|}{$N_{27}$}
  58. & \multicolumn{1}{>{\centering\arraybackslash}c|}{$N_{28}$}
  59. & \multicolumn{1}{>{\centering\arraybackslash}c|}{$N_{29}$}
  60. \\ \hline
  61. \multicolumn{1}{|c|}{$L$}
  62. & \multicolumn{29}{c|}{Wow ! LaTeX is fun !}
  63. \\ \hhline{|=|=|=|=|=|=|=|=|=|=|=|=|=|=|=|=|=|=|=|=|=|=|=|=|=|=|=|=|=|=|}
  64. 0 & 300 & 300 & 300 & 300 & 300 & 300 & 300 & 300 & 300 & 300 & 300 & 300 & 300 & 300 & 300 & 300 & 300 & 300 & 300 & 300 & 300 & 300 & 300 & 300 & 300 & 300 & 300 & 300 & 300
  65. \\ \hline
  66. 1 & 281 & 282 & 283 & 285 & 283 & 282 & 283 & 283 & 277 & 285 & 279 & 282 & 285 & 279 & 284 & 278 & 284 & 276 & 281 & 286 & 279 & 290 & 277 & 284 & 290 & 282 & 290 & 286 & 281
  67. \\ \hline
  68. \end{tabular}
  69. \end{adjustbox}
  70. \caption{Some very funny caption. LOL!}
  71. \end{table}
  72. \end{landscape}
  73.  
  74. \end{document}


Is this the best way of doing this ? I need opinions on the code above.

Any suggestions to improve the code and the output ?

User avatar
Stefan Kottwitz
Site Admin
Posts: 8529
Joined: Mon Mar 10, 2008 9:44 pm
Location: Hamburg, Germany
Contact:

Postby Stefan Kottwitz » Fri Nov 10, 2017 4:11 pm

Well, output: I generally don't like a full grid for tables, locking all in cells. I like some supporting structure by decent horizontal lines only. I never do double lines.

Code: I would put repeated things into a macro, such as for \multicolumn{1}{>{\centering\arraybackslash}c|}{$...$}

Stefan
Site admin

rais
Posts: 149
Joined: Sun Nov 16, 2014 8:51 pm

Postby rais » Fri Nov 10, 2017 7:43 pm

Well, considering that in the tabular's column declaration, you already stated `c' as the column type to use, a \multicolumn{1}{[[|]>{...}]c[|]} seems superfluous.
Even if those differ (`those' meaning the column specifications in {tabular} and within the matching \multicolumn statement), a construct like
\multicolumn{1}{|>{\centering\arraybackslash}c|}{$t$} seems odd in its own way: `centering' a centered cell?
Not to mention that \arraybackslash is---usually---just needed in the last cell of a row.

In short, I'd replace those `\multicolumn{1}{<something with `c' as column spec>}{<...>} with <...>, e.g.,
  1. \multicolumn{1}{|>{\centering\arraybackslash}c|}{$t$}

would come to:

KR
Rainer

User avatar
Cham
Posts: 819
Joined: Sat Apr 02, 2011 4:06 pm

Postby Cham » Fri Nov 10, 2017 8:01 pm

Thanks for the feedback. I'll check all of these suggestions.


Return to “Graphics, Figures & Tables”

Who is online

Users browsing this forum: No registered users and 10 guests