18

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} 
3
  • 1
    replace sidewaystable by landscape and add lscape or pdflscape package May 3, 2015 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 3, 2015 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 4, 2015 at 0:45

1 Answer 1

22

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 & 9 & 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& 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 \\
 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

4
  • 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} Oct 22, 2018 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, 2018 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 9, 2020 at 14:25
  • @pauljohn32 - Please see the addendum I posted to address your comment.
    – Mico
    Dec 10, 2020 at 9:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.