LaTeX forum ⇒ Graphics, Figures & TablesTable in multicolumn environment

Information and discussion about graphics, figures & tables in LaTeX documents.
Posts: 2
Joined: Mon Sep 14, 2020 4:04 pm

Table in multicolumn environment

Postby lucia_ » Mon Sep 14, 2020 5:02 pm

Hi there,

I want to include a very long and narrow table in a Latex document. (I am in \documentclass{amsart} if that is relevant.) The table has almost 3000 rows and 3 narrow columns. When I inserted it using the normal tabular environment it spanned almost 80 pages!

Therefore, I would like to insert the table in a multicolumn environment, preferably with 3 columns, in order to save space. I would like the headings of the table to repeat each time the table starts in a new column. I would like to add a caption to the table which repeats on each new page. Finally, I would like the table to sit nicely with the rest of my text (it is part of an essay).

I am not an experienced user of Latex and pieced together some advice from forums online. Below is what I came up with. I would really appreciate some advice on how to improve on the problems I am having with what I have written so far. Alternatively, let me know if you have a better way of going about this.

I found some advice online saying to use the environment xtabular and the multicolumn environment, which I have transferred my table to, but I am having some problems.
- Originally I started the table midpage, after some other text relating to it. This meant that the table only had about 5 rows before it went onto the next column. This was fine for the first page. However, it continued only doing 5 rows in each column on the next new page i.e. not filling up the entire page! As a temporary fix, I added \newpage before the table, so now the table is spanning an entire page, but it means that I have a gap in my document. So, my first problem is getting the table to format nicely with the rest of the text. If it is necessary for the table to start on a newpage, that would be ok. As long as the text after the table filled the gap that it has left.
- My second problem is that the table is exceeding the margins which the rest of the text sits in. It seems to be fine everywhere except the bottom margin, where it is going over the page number and close to the bottom of the page.
- I don't know how to add a caption which repeats on every page that the table is on.
- This is a weird one. Only on the first column of the first page that the table is on, the table is finishing 1 row earlier than the entire rest of it.

This is in the preamble:
Code: [Select all] [Expand/Collapse] [Download] ({untitled.tex})
  1. \maxdeadcycles=5000
  2. \makeatletter
  3. \let\mcnewpage\newpage
  4. \newcommand{\changenewpage}{%
  5. \renewcommand\newpage{%
  6. \if@firstcolumn
  7. \hrule width\linewidth height0pt
  8. \columnbreak
  9. \else
  10. \mcnewpage
  11. \fi
  12. }}
  13. \makeatother

And in the main body of the document (I have changed the contents of the table):
Code: [Select all] [Expand/Collapse] [Download] ({untitled.tex})
  1. \newpage
  2. \begin{multicols*}{3}
  3. \changenewpage
  5. \tablehead{\toprule
  6. Apple & Banana & Orange \\*}
  7. \begin{xtabular}{
  8. >{\centering\arraybackslash}p{\dimexpr.4\columnwidth-6\tabcolsep}
  9. >{\centering\arraybackslash}p{\dimexpr.5\columnwidth-6\tabcolsep}
  10. >{\centering\arraybackslash}p{\dimexpr.4\columnwidth-6\tabcolsep}}
  11. \midrule
  12. 1 & 2 & 3 \\* \midrule
  13. 1 & 2 & 3 \\* \midrule
  14. 1 & 2 & 3 \\* \midrule
  15. 1 & 2 & 3 \\* \midrule
  16. %etc...
  17. 1 & 2 & 3 \\* \bottomrule
  18. \label{table:results}
  19. \end{xtabular}
  20. \end{multicols*}

If I have not explained my problem well or you need any more information to help solve the problem, let me know! :)

User avatar
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Postby Johannes_B » Tue Sep 15, 2020 4:56 am

First question I asked myself: who would read 3000 rows of data? Is there any way you can convert your data into a plot of some sort?
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.

Posts: 2
Joined: Mon Sep 14, 2020 4:04 pm

Postby lucia_ » Tue Sep 15, 2020 10:51 am

Hi Johannes,

Unfortunately, a plot would not be possible. But, now that you say that, you have inspired me to think that perhaps I could condense the data down in a different, more palatable way... Thanks! :)

For future reference, regarding the method that I was describing to construct a table over multiple columns, would you agree with the method that I used? Do you have any advice on how it could be better? Hate to leave a problem unsolved!



Return to “Graphics, Figures & Tables”

Who is online

Users browsing this forum: No registered users and 5 guests