22

I would like to spread my vertical table over multiple pages. I tried it with sidewaystable and longtable, but that put everything on one page. Another idea would be just to create x tables, where x stands for the number of needed pages. That would work, but I would like to have a more convenient solution. Is there any?

\documentclass[11pt,paper=a4,]{scrbook}
\usepackage{longtable}            
\usepackage{rotating}

\begin{document}

   \begin{sidewaystable}
      \begin{longtable}[c]{|p{5cm}|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|}
         \hline
          0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 & 13 & 14 & 15 \\
          \hline
      \end{longtable}
   \end{sidewaystable}
\end{document} 
Mico
  • 506,678
flp
  • 459
  • 1
    replace sidewaystable by landscape and add lscape or pdflscape package – David Carlisle May 03 '15 at 22:58
  • Welcome to TeX SE! I'm a bit confused by your question. Your example involves a table which does not need longtable at all because it only has one row. And it will surely fit on one page horizontally, too. Is your actual table (i) too long (ii) too wide or (iii) both? Are you rotating it because it is too wide for portrait but fits in landscape mode? If so, the trick would be to use something other than sidewaystable which will prevent page breaks. Switching to landscape mode would let you do this, for example. – cfr May 03 '15 at 23:01
  • @cfr: I left out the lines which would overflow the page because I thought it isn't necessary and just complicates my code. My current table is too wide for horizontal and too long for one vertical page. I will try the landscape mode – flp May 04 '15 at 00:45

1 Answers1

24

The sidewaystable environment does not let you split its contents across multiple pages. Since you're using a longtable environment, which has its own \caption commands, etc., there's no real need to embed it in a sidewaystable environment anyway. Instead, consider loading the pdflscape package and using that package's landscape environment to rotate the material by 90 degrees.

\documentclass[11pt,paper=a4]{scrbook}
\usepackage{longtable} % for 'longtable' environment
\usepackage{pdflscape} % for 'landscape' environment
\begin{document}
\chapter{Hello}
\section{World}

\begin{landscape} \begin{longtable}{ | p{5cm} | *{15}{c|} } \hline\endhead % header material \hline\endfoot % footer material 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 & 13 & 14 & 15 \ 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 &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 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 & 13 & 14 & 15 \ 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 & 13 & 14 & 15 \ 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 & 13 & 14 & 15 \ 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 & 13 & 14 & 15 \ 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 & 13 & 14 & 15 \ 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 & 13 & 14 & 15 \ 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 & 13 & 14 & 15 \ \end{longtable} \end{landscape} \end{document}


Addendum to address a comment by @pauljohn32: If the longtable and pdflscape packages are loaded and if a halfway-competent pdf viewer is in use, the landscape/longtable combination (a) rotates the tabular material 90 degrees counterclockwise to landscape format and (b) ensures that the onscreen display of the pages with the tabular material is also rotated, so that readers don't have to crane their necks in order to take in the tabular information. However, this combination does not make the pages into "landscape pages"; i.e., the header and footer lines are still placed where they'd go in portrait mode. In the following screenshot, I've highlighted the MWE's header and footer lines in yellow to demonstrate this fact. (Of course, what exactly is placed on the header and footer lines depends on factors such as the document class in use. However, that's a separate issue, isn't it?)

enter image description here

Mico
  • 506,678
  • 1
    (I would put this in a comment but I don't have enough reputation) @Mico 's solution didn't work for my until I changed:\usepackage{pdflscape} to \usepackage{lscape} – LabviewMustDie Oct 22 '18 at 17:06
  • 1
    @LabviewMustDie - In order for your comment to be (more) helpful to future readers of this posting and, in particular, for readers to understand readily why you found it was necessary to switch from the pdflscape package to the lscape package, you should provide some extra information about your computing environment. E.g., which engine do you use to compile your documents: pdfLaTeX, XeLaTeX, or LuaLaTeX? And, which document class do you employ? – Mico Oct 22 '18 at 19:39
  • We ran into a problem with this answer at our University. The rules for dissertation forbid any landscape pages. It is OK to rotate a table, but if the page itself becomes landscape, then it is rejected. I've not found any solution that allows longtable with rotated table. – pauljohn32 Dec 09 '20 at 14:25
  • @pauljohn32 - Please see the addendum I posted to address your comment. – Mico Dec 10 '20 at 09:19
  • Regarding @pauljohn32 's comment and the edit to the answer, is there a way to get the footer where it would be for a landscape page? – climatestudent May 10 '23 at 08:40
  • @climatestudent - Please clarify what you mean by "get the footer where it would be for a landscape page". Please also state which document class you employ. – Mico May 10 '23 at 08:59
  • @Mico, sorry, I mean to place the footer at the bottom of the page, when viewed in landscape orientation, which would be the right-hand long edge in portrait orientation. I'm using the report document class, with options a4paper, 12pt, in case that matters. – climatestudent May 10 '23 at 12:47
  • @climatestudent - Speaking for myself, I find it difficult to read a document in which the positions of the page headers and footers bounce around according to whether the page is typeset in portrait or landscape mode. Can you arrange to suppress the footer(s) on the landscape-oriented pages? – Mico May 10 '23 at 13:03
  • @Mico, thanks, fair enough, for my part I find it hard to read a page in which some text is oriented in a direction orthogonal to the majority of the text. Yes, I have removed the footers, but this leads to a somewhat excessive (and unsightly) left margin (when the page is viewed in landscape orientation). But this is a different concern, for which I will try to find a solution. Thank you for the rapid responses! – climatestudent May 10 '23 at 23:30