2

I can create a longtable with numprint:

\documentclass{article}

\usepackage{numprint}
\usepackage{longtable}

\npdecimalsign{,}
\nprounddigits{2}

\begin{document}
\begin{longtable}{n{3}{2}}
-11,82405 \\[12ex] -12,44918 \\[12ex] -12,45381 \\[12ex] -12,52252 \\[12ex] -12,56154 \\[12ex] -12,41009 \\[12ex] -12,44918 \\[12ex] -12,41009 \\[12ex] -12,51782 \\[12ex] -12,48817 \\[12ex] -12,52252 \\[12ex] -12,56611 \\[12ex] -12,44918 \\[12ex] -12,37081 \\
\end{longtable}
\end{document}

However, I want to have the table rotated. (the MWE just shows a single one of several rows) I can do this with a regular tabular and sideways just fine:

\documentclass{article}

\usepackage{numprint}
\usepackage{rotating}

\begin{document}

\npdecimalsign{,}
\nprounddigits{2}
\begin{sideways}
\begin{tabular}{c|n{3}{2}||n{3}{2}|n{3}{2}|n{3}{2}|n{3}{2}|n{3}{2}|n{3}{2}|n{3}{2}|n{3}{2}|n{3}{2}|n{3}{2}|n{3}{2}|n{3}{2}|n{3}{2}}
& foo & \multicolumn{13}{c}{bar}\\
\hline
 & -11,82405 & -12,44918 & -12,45381 & -12,52252 & -12,56154 & -12,41009 & -12,44918 & -12,41009 & -12,51782 & -12,48817 & -12,52252 & -12,56611 & -12,44918 & -12,37081 \\
\end{tabular}
\end{sideways}
\end{document}

All I get is an overfull HBox due to the height of the table. When I try to fix this with longtable, it explodes in my face with dozens of error messages that I do not understand at all:

\documentclass{article}

\usepackage{numprint}
\usepackage{rotating}

\usepackage{longtable}

\begin{document}

\npdecimalsign{,}
\nprounddigits{2}
\begin{sideways}
\begin{longtable}{c|n{3}{2}||n{3}{2}|n{3}{2}|n{3}{2}|n{3}{2}|n{3}{2}|n{3}{2}|n{3}{2}|n{3}{2}|n{3}{2}|n{3}{2}|n{3}{2}|n{3}{2}|n{3}{2}}
& foo & \multicolumn{13}{c}{bar}\\
\hline
 & -11,82405 & -12,44918 & -12,45381 & -12,52252 & -12,56154 & -12,41009 & -12,44918 & -12,41009 & -12,51782 & -12,48817 & -12,52252 & -12,56611 & -12,44918 & -12,37081 \\
\end{longtable}
\end{sideways}
\end{document}

I use TexMaker 4.4.1, which didn't let me copy all the messages at once so I made a screenshot:

error messages

It looks like its complaining about internal stuff. I have the feeling that the environments sideways and longtable do not go together well. Is this the case? How do I solve this?

Use the landscape environment (from lscape or pdflscape packages) to rotate a longtable.

That doesn't seem to work. Using landscape instead of sideways, the longtable is not distributed across multiple pages, but shoots out above the top of page 1, as can be seen on the right in the following screenshot:

enter image description here

\documentclass{article}
\usepackage{numprint}
\usepackage{lscape}
\usepackage{longtable}
\begin{document}

\npdecimalsign{,}
\nprounddigits{2}
\begin{landscape}
\begin{longtable}{c|n{3}{2}||n{3}{2}|n{3}{2}|n{3}{2}|n{3}{2}|n{3}{2}|n{3}{2}|n{3}{2}|n{3}{2}|n{3}{2}|n{3}{2}|n{3}{2}|n{3}{2}|n{3}{2}|n{3}{2}|n{3}{2}|n{3}{2}|n{3}{2}|n{3}{2}|n{3}{2}|n{3}{2}|n{3}{2}|n{3}{2}}
& foo & \multicolumn{13}{c}{bar}\\
\hline
 & -11,82405 & -12,44918 & -12,45381 & -12,52252 & -12,56154 & -12,41009 & -12,44918 & -12,41009 & -12,51782 & -12,48817 & -12,52252 & -12,56611 & -12,44918 & -12,37081 & -12,37081 & -12,37081 & -12,37081 & -12,37081 & -12,37081 & -12,37081 & -12,37081 & -12,37081 & -12,37081 \\
\end{longtable}
\end{landscape}
\end{document}
null
  • 265
  • note the summary of the messages in the editor is often confusing (for example they omit to show the command which is undefined when showing the undefined command error) , the real messages are always available in the log file, which you can easily cut and paste to the site. – David Carlisle Oct 03 '16 at 21:17
  • the new example even landscape is Overfull \hbox (388.49103pt too wide) 389pt is over 5 in or 13cm it just doesn't fit, you need to use \small or \tiny and reduce the inter-column space or use less decimal place or.... that is unrelated to it being multi-page landscape, which works fine as you will see if you add more rows – David Carlisle Oct 03 '16 at 21:49
  • @DavidCarlisle I was hoping there's a way to rotate the table such that the mechanism that breaks the table into multiple pages recognises that it's now the additional columns that should go onto the new page and not the additional rows. – null Oct 03 '16 at 21:54
  • no, that's not how it works. It page breaks between rows not between columns. – David Carlisle Oct 03 '16 at 21:55

1 Answers1

2

Use the landscape environment (from lscape or pdflscape packages) to rotate a longtable.


\documentclass{article}

\usepackage{numprint}
\usepackage{lscape}

\usepackage{longtable}

\begin{document}

\npdecimalsign{,}
\nprounddigits{2}
\begin{landscape}
\setlength\tabcolsep{5pt}
\begin{longtable}{c|n{3}{2}||*{13}{n{3}{2}|}}
& foo & \multicolumn{13}{c}{bar}\\
\hline
 & -11,82405 & -12,44918 & -12,45381 & -12,52252 & -12,56154 & -12,41009 & -12,44918 & -12,41009 & -12,51782 & -12,48817 & -12,52252 & -12,56611 & -12,44918 & -12,37081 \\
\end{longtable}
\end{landscape}
\end{document}
David Carlisle
  • 757,742
  • I created an example myself before seeing that you added an example to your answer. I could not get it to work. The table does not split across pages (I edited my question to include my new code with landscape in it and what result I get). Now that I have seen your example, the only difference I can spot is \setlength\tabcolsep{5pt} but that doesn't make it work either. What am I missing here? Have an upvote for the *{13} notation that I didn't know before. – null Oct 03 '16 at 21:37
  • @null you only show an image which is no use to test, if you try the code above you will find that it is rotated, if you add code to your question people can debug it. – David Carlisle Oct 03 '16 at 21:42
  • You're absolutely right, I forgot to add the code. I added some more cells to the table to force the issue. – null Oct 03 '16 at 21:47
  • 1
    @null there is no problem with the rotation or multi-page aspect (try adding many rows) your rows are simply too long to fit on a line even landscape. You could try using \tiny but it is still too big (and unreadable) best would be to use subject knowledge to re-think the display format. No one can read the data displayed this way. – David Carlisle Oct 03 '16 at 21:54
  • Ok, I guess my question is answered, albeit not in the way I had hoped for. I thought I already came up with a way to display this data in a minimal way, but the concerns you raise are very valid. I will rethink this and try to come up with a different way. Thank you for your input. – null Oct 03 '16 at 21:59
  • There is some code to split on columns but i wouldn't use it unless you had an existing database dump and reformatting the table was really inconvenient http://tex.stackexchange.com/questions/93808/column-wise-break-of-extra-wide-tables/93810#93810 (@null) – David Carlisle Oct 03 '16 at 22:04