LaTeX forum ⇒ Graphics, Figures & TablesQuestions regarding multi-page tables

Information and discussion about graphics, figures & tables in LaTeX documents.
insipidtoast
Posts: 128
Joined: Wed Jul 04, 2012 5:34 pm

Questions regarding multi-page tables

Postby insipidtoast » Sun Sep 16, 2012 1:28 am

When I'm using Lyx, my tables often end up going off the bottom of the page! I don't want that to happen.

Why don't tables pagebreak?

How can I make it so ALL the tables in my book will just follow the same formatting rules (regarding pagebreaks) as paragraphs of text?

Please note that most of my tables are within a multicolumn environment, because I need to have them side-by-side in order to save space, and not have too many extra pages in my book. (There are lots of long tables in my book).

CTAN says:
Longtable arranges that the columns on successive pages have the same widths. This last contrasts with the superficially similar supertabular package.

So, I want to have the columns be the same widths after they pagebreak, but CTAN also states that Longtable doesn't work in a multicolumn environment.

So I'm not sure, which package to use. Please tell me what package I should use, and also briefly tell me HOW to use it.

Thanks
FYI:
I'm using windows with LyX 2.0 and MiKTeX 2.9
I'm designing a book using the Koma-script class

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Questions regarding multi-page tables

Postby cgnieder » Sun Sep 16, 2012 12:22 pm

Tables that allow page breaks are not an easy thing in LaTeX. I know of two packages that try to implement a solution. Both have their pros and cons. As you've noticed longtable won't work in \twocolumn. So maybe you could give supertabular a try:

\documentclass[twocolumn]{scrbook}
\usepackage{supertabular}

\usepackage{kantlipsum}% for dummy text

\begin{document}
\chapter{test}
\kant[1-4]

\begin{center}
\tablefirsthead{%
  \hline
  \multicolumn{1}{|c}{ $n$ } &
  \multicolumn{1}{c}{ $n^2$ } &
   $n^4$ &
  \multicolumn{1}{c|}{ $n!$ } \\
  \hline}
\tablehead{%
  \hline
  \multicolumn{4}{|l|}{\small\sl continued from previous page}\\
  \hline
  \multicolumn{1}{|c}{ $n$ } &
  \multicolumn{1}{c}{ $n^2$ } &
   $n^4$ &
  \multicolumn{1}{c|}{ $n!$ } \\
  \hline}
\tabletail{%
  \hline
  \multicolumn{4}{|r|}{\small\sl continued on next page}\\
  \hline}
\tablelasttail{\hline}
\bottomcaption{This table is split across pages}
%
\begin{supertabular}{|r|r|r|r|}
1 &  1  &        1  &           1    \\
2   &     4  &       16  &           2    \\
3   &     9  &       81  &           6    \\
4   &    16  &      256  &          24    \\[5mm]
5   &    25  &      625  &         120    \\
6   &    36  &     1296  &         720    \\
7   &    49  &     2401  &        5040    \\
8   &    64  &     4096  &       40320    \\
9   &    81  &     6561  &      362880    \\
10  &   100  &    10000  &     3628800    \\
1 &  1  &        1  &           1    \\
2   &     4  &       16  &           2    \\
3   &     9  &       81  &           6    \\
4   &    16  &      256  &          24    \\[5mm]
5   &    25  &      625  &         120    \\
6   &    36  &     1296  &         720    \\
7   &    49  &     2401  &        5040    \\
8   &    64  &     4096  &       40320    \\
9   &    81  &     6561  &      362880    \\
10  &   100  &    10000  &     3628800    \\
\end{supertabular}
\end{center}

\kant[4-6]
\end{document}


supertabular.png
supertabular.png (142.2 KiB) Viewed 18205 times


Regards
site moderator & package author

insipidtoast
Posts: 128
Joined: Wed Jul 04, 2012 5:34 pm

Questions regarding multi-page tables

Postby insipidtoast » Sun Sep 16, 2012 9:02 pm

Hey man, thanks for your response, but that goes way over my head.

Here's the sort of format I'm trying to make (In LyX of course, because I don't want to deal with reading all that code all the time). I'm really happy with the way this looks in my pdf preview. However, if this same table occurs further down the page, then the table(s) gets cut off and part of it disappears off the bottom of the page. That's what I'm trying to avoid.

\begin{multicols}{2}

\noindent %
\begin{tabular}{|l|l|}
\hline 
\multicolumn{1}{|l}{Fruits:} & \tabularnewline
\hline 
\textbf{\footnotesize Nutrient:} & \textbf{\footnotesize Unit per 100g:}\tabularnewline
\hline 
{\footnotesize Water} & {\footnotesize 82.3g}\tabularnewline
\hline 
{\footnotesize Energy} & {\footnotesize 61kcal}\tabularnewline
\hline 
{\footnotesize Protein} & {\footnotesize 2.1g}\tabularnewline
\hline 
{\footnotesize Fat} & {\footnotesize 0.2g}\tabularnewline
\hline 
{\footnotesize Carbohydrates} & {\footnotesize 13g}\tabularnewline
\hline 
{\footnotesize Fiber} & {\footnotesize 1.3g}\tabularnewline
\hline 
{\footnotesize Calcium} & {\footnotesize 38mg}\tabularnewline
\hline 
{\footnotesize Magnesium} & {\footnotesize 2mg}\tabularnewline
\hline 
{\footnotesize Phosphorous} & {\footnotesize 24mg}\tabularnewline
\hline 
{\footnotesize Iron} & {\footnotesize 0.2mg}\tabularnewline
\hline 
{\footnotesize Thiamin} & {\footnotesize 0.19mg}\tabularnewline
\hline 
{\footnotesize Riboflavin} & {\footnotesize 0.13mg}\tabularnewline
\hline 
{\footnotesize Ascorbic Acid} & {\footnotesize 25mg}\tabularnewline
\hline 
\end{tabular}{\footnotesize }\\
{\footnotesize Source: PROTA 2: \newline Vegetables/Légumes}{\footnotesize \par}

\noindent %
\begin{tabular}{|l|l|}
\hline 
\multicolumn{1}{|l}{Caudex:} & \tabularnewline
\hline 
\textbf{\footnotesize Nutrient:} & \textbf{\footnotesize Unit per 100g:}\tabularnewline
\hline 
{\footnotesize Water} & {\footnotesize 84g}\tabularnewline
\hline 
{\footnotesize Energy} & {\footnotesize 47kcal}\tabularnewline
\hline 
{\footnotesize Protein} & {\footnotesize 1.0g}\tabularnewline
\hline 
{\footnotesize Fat} & {\footnotesize 0.1g}\tabularnewline
\hline 
{\footnotesize Carbohydrates} & {\footnotesize 11g}\tabularnewline
\hline 
{\footnotesize Fiber} & {\footnotesize 2.7g}\tabularnewline
\hline 
{\footnotesize Calcium} & {\footnotesize 351mg}\tabularnewline
\hline 
{\footnotesize Magnesium} & {\footnotesize 60mg}\tabularnewline
\hline 
{\footnotesize Phosphorous} & {\footnotesize 40mg}\tabularnewline
\hline 
{\footnotesize Iron} & {\footnotesize 2.2mg}\tabularnewline
\hline 
{\footnotesize Thiamin} & {\footnotesize 0.02mg}\tabularnewline
\hline 
{\footnotesize Riboflavin} & {\footnotesize 0.01mg}\tabularnewline
\hline 
{\footnotesize Niacin} & {\footnotesize 0.28mg}\tabularnewline
\hline 
{\footnotesize Ascorbic Acid} & {\footnotesize 6.7mg}\tabularnewline
\hline 
\end{tabular}

\noindent \end{multicols} 
FYI:
I'm using windows with LyX 2.0 and MiKTeX 2.9
I'm designing a book using the Koma-script class

User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Questions regarding multi-page tables

Postby cgnieder » Sun Sep 16, 2012 9:19 pm

Standard tables like tabular cannot have page breaks inside of them them! As I said: there are only two possibilities, either the longtable package (doc: longtable) or the supertabular package (doc: supertabular). As far as I know LyX does not support them implicitly so I fear you're going to have to study their manuals and insert the code manually if you insist that you're tables should be allowed to break.

IMHO one should avoid page breaks in tables if possible. They should have captions and numbers so they can be referenced. This makes it possible that they don't need to have a fixed position in the text. In my opinion only if a table is too long to fit on a page one should allow it to break.

Regards
site moderator & package author

insipidtoast
Posts: 128
Joined: Wed Jul 04, 2012 5:34 pm

Re: Questions regarding multi-page tables

Postby insipidtoast » Sun Sep 16, 2012 9:47 pm

Oh man! Are you serious? That's what I was afraid of. I don't have the slightest clue how to make tables using pure code. And yes, some of my tables are LOOOONG!

Ugh. So, it's time to learn Chinese, eh?

How do you even do that in Lyx? Just put everything inside of a big ERT box?

Just looking at the tutorial for supertabular...are you sure there isn't another way? That looks like a royal pain in the butt? There isn't another package that's more user friendly? Theoretically I could just figure out where the table cuts into the margin, then create two new tables, right? One table (half of the original table) on one page, and another table (2nd half of the original table) on the next page. Would this work in a multicolumns environment?

I tried putting those same multicolumns I showed above into a table float, but that doesn't even work. Oh gosh, I thought lyx would have plenty of straightforward table formatting options.......
FYI:
I'm using windows with LyX 2.0 and MiKTeX 2.9
I'm designing a book using the Koma-script class

User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Questions regarding multi-page tables

Postby cgnieder » Sun Sep 16, 2012 9:55 pm

insipidtoast wrote:How do you even do that in Lyx? Just put everything inside of a big ERT box?


I haven't created a single document with LyX so I wouldn't know... in the worst case: yes.

insipidtoast wrote:Just looking at the tutorial for supertabular...are you sure there isn't another way?

Pretty much...

insipidtoast wrote:I tried putting those same multicolumns I showed above into a table float, but that doesn't even work. Oh gosh, I thought lyx would have plenty of straightforward table formatting options.......


It is said that D.E.Knuth (he who invented TeX) is quoted regarding tables along the lines: „I'm still surprised it works“. Tables are not LaTeX's strongest side...

Regards
site moderator & package author

insipidtoast
Posts: 128
Joined: Wed Jul 04, 2012 5:34 pm

Re: Questions regarding multi-page tables

Postby insipidtoast » Sun Sep 16, 2012 10:03 pm

Oh man, I wish I knew that before I started. That would've been a deal breaker.

What do I do?
FYI:
I'm using windows with LyX 2.0 and MiKTeX 2.9
I'm designing a book using the Koma-script class

ng0323
Posts: 3
Joined: Tue Jul 15, 2014 4:25 am

Re: Questions regarding multi-page tables

Postby ng0323 » Sun Jul 20, 2014 8:22 pm

I want to produce a multi-page table with caption that spans columns in a two-column document (document class for Springer journal.)
Longtable doesn't like two-column documents. So I tried putting the table between \onecolumn and \twocolumn but it's pretty tricky. It seems that one and two columns cannot exist in the same page this way. Also, Lyx didn't allow me to caption it.
Since, supertabular was suggested above, how easy is it to transfer the code (containing the table contents) from longtable to supertabular? It would kill me to have to code all the table contents. I have already typed up the tables contents in Lyx, and have them display nicely in a float table, then I found out they won't continue to the next page. It would be great if I can just copy the code containing the contents, and if the difference between longtable and supertabular are just a few lines at the beginning of the code.
Furthermore, it would be best that I can caption the tables in each page (e.g. Table 2 (continued) in the following pages) and the table numbering follows from the other float tables (this is a must). At the moment I have no idea how this can be done.


Return to “Graphics, Figures & Tables”

Who is online

Users browsing this forum: Google [Bot] and 4 guests