0

I have several long tables in my document, some of which are in landscape mode. When a table is "landscaped" using sidewaystable, although the table is in the next full page, the text continues as usual until it fills the previous page (see first image). This is the expected behaviour, identical to normal tables or figures --for which Latex finds "the best position" and the text before and after the table/figure continues as usual.

As my tables are long, I need to use landscape from the package pdflscape or lscape. However, when using either of them, the text after the table is not continuing as usual to fill the previous page (see second image).

Is there any way around this? I'd like to be able to obtain the same behaviour of sidewaystable (actually, the usual behaviour) for my long landscaped tables.

MWE (change the comment from the \begin and \end{landscape} to those of sidewaystable to exchange the result):

\documentclass[11pt, a4paper, oneside]{report}
\usepackage[left=4cm,right=2cm,top=2.5cm,bottom=2.5cm]{geometry}
\usepackage{xltabular}
\usepackage{pdflscape}
\usepackage{lipsum}
\usepackage{rotating}

\begin{document}

\setlength{\parskip}{6pt}
\lipsum[23]

\begin{sidewaystable}
% \begin{landscape}
 \setlength\LTcapwidth{\linewidth} % I need that for long captions
{\small
\begin{xltabular}{\linewidth}{@{} XXXX @{}}
\caption{{\normalsize This is a caption.\label{table:bla}}}\\
\hline
Column 1 & Column 2 & Column 3 & Column 4 \\
\hline
\endfirsthead
\multicolumn{4}{c}%
{\footnotesize{\tablename\ \thetable\ -- \textit{Continued from previous page}}} \\ \hline
Column 1 & Column 2 & Column 3 & Column 4 \\
\hline
\endhead
\lipsum[2][3-5] & \lipsum[2][3-5] & \lipsum[2][3-5] & \lipsum[2][3-5]   \\ \hline
\lipsum[2][3-5] & \lipsum[2][3-5] & \lipsum[2][3-5] & \lipsum[2][3-5]   \\ \hline
\lipsum[2][3-5] & \lipsum[2][3-5] & \lipsum[2][3-5] & \lipsum[2][3-5]   \\ \hline
\lipsum[2][3-5] & \lipsum[2][3-5] & \lipsum[2][3-5] & \lipsum[2][3-5]   \\ \hline
\lipsum[2][3-5] & \lipsum[2][3-5] & \lipsum[2][3-5] & \lipsum[2][3-5]   \\ \hline
\lipsum[2][3-5] & \lipsum[2][3-5] & \lipsum[2][3-5] & \lipsum[2][3-5]   \\ \hline
\lipsum[2][3-5] & \lipsum[2][3-5] & \lipsum[2][3-5] & \lipsum[2][3-5]   \\ \hline
\lipsum[2][3-5] & \lipsum[2][3-5] & \lipsum[2][3-5] & \lipsum[2][3-5]   \\ \hline
\end{xltabular}}
% \end{landscape}
\end{sidewaystable}

\lipsum[1]

\lipsum[2]

\lipsum[3]

\end{document}

Result using sidewaystable (the table does not break to change the page but the text behaves "correctly"): sidewaystable

Result using landscape (the table does break to change the page but the text behaves "wrongly"): enter image description here

  • 1
    sidewaystable is a float like table so can never break over a page, use the landscape enviornment from the lscape or pdflscape package. – David Carlisle May 26 '20 at 18:01
  • @DavidCarlisle Yes, that's what I do. However, the text is then broken at the position of the table in the code. What I want is the text to behave "normally", i.e., continue until it fills the page. Here I only use sidewaystable to show the behaviour I want the text to have. – Miquel May 26 '20 at 18:25
  • 2
    well that's the choice. floats do not split. Personally I'd remove the longtable run latex so that I see the good page break then re-insert the table at that point so you get a natural page break. A bit of effort but fewer keystrokes than it takes to write this comment. – David Carlisle May 26 '20 at 18:28
  • also please remove all the mis-placed \\ after lipsum that tex is warning about Underfull \hbox (badness 10000) in paragraph at lines 10--11 – David Carlisle May 26 '20 at 18:30
  • 1
    \\ does not finish the paragraph that is the problem, it should never be used at the end of a paragraph it should (vary rarely) be used to force a line break mid-paragraph. A paragraph is ended by a blank line in the source. tex.stackexchange.com/questions/334246/… – David Carlisle May 26 '20 at 21:24
0

There doesn't seem to be a way to solve this problem, and I only found a dodgy workaround:

As @DavidCarlisle says in the comments of the question, you can run the code without the table to check where you have to introduce the table. What you want is to break the paragraph in your code in the same place where the latex breaks the page. To do that you can use \linebreak so that the last sentence in the page is justified, introduce the table, and start the rest of the text with \noindent.

However, this leads to having a blank page before the table. Therefore, instead of adding \linebreak where the last line of the page ends, you have to add it where the previous line ends:

Place <code>\linebreak</code> after "mi."

See MWE:

\documentclass[11pt, a4paper, oneside]{report}
\usepackage[left=4cm,right=2cm,top=2.5cm,bottom=2.5cm]{geometry}

\usepackage{xltabular}
\usepackage{pdflscape}
\usepackage{lipsum}
\usepackage{rotating}

\begin{document}

\setlength{\parskip}{6pt}
\lipsum[2-7]

Nam dui ligula, fringilla a, euismod sodales, sollicitudin vel, wisi. Morbi auctor loremnon justo. Nam lacus libero, pretium at, lobortis vitae, ultricies et, tellus. Donec aliquet, tortor sed accumsan bibendum, erat ligula aliquet magna, vitae ornare odio metus a mi. \linebreak % As seen when running the code without the table, here is where the previous to the last line of the page ends.

\begin{landscape}
\setlength\LTcapwidth{\linewidth}
{\small
\begin{xltabular}{\linewidth}{@{} XXXX @{}}
\caption{{\normalsize This is a caption.\label{table:bla}}}\\
\hline
Column 1 & Column 2 & Column 3 & Column 4 \\
\hline
\endfirsthead
\multicolumn{4}{c}%
{\footnotesize{\tablename\ \thetable\ -- \textit{Continued from previous page}}} \\ \hline
Column 1 & Column 2 & Column 3 & Column 4 \\
\hline
\endhead
\lipsum[2][3-5] & \lipsum[2][3-5] & \lipsum[2][3-5] & \lipsum[2][3-5]   \\ \hline
\lipsum[2][3-5] & \lipsum[2][3-5] & \lipsum[2][3-5] & \lipsum[2][3-5]   \\ \hline
\lipsum[2][3-5] & \lipsum[2][3-5] & \lipsum[2][3-5] & \lipsum[2][3-5]   \\ \hline
\lipsum[2][3-5] & \lipsum[2][3-5] & \lipsum[2][3-5] & \lipsum[2][3-5]   \\ \hline
\lipsum[2][3-5] & \lipsum[2][3-5] & \lipsum[2][3-5] & \lipsum[2][3-5]   \\ \hline
\lipsum[2][3-5] & \lipsum[2][3-5] & \lipsum[2][3-5] & \lipsum[2][3-5]   \\ \hline
\lipsum[2][3-5] & \lipsum[2][3-5] & \lipsum[2][3-5] & \lipsum[2][3-5]   \\ \hline
\lipsum[2][3-5] & \lipsum[2][3-5] & \lipsum[2][3-5] & \lipsum[2][3-5]   \\ \hline
\end{xltabular}}
\end{landscape}

\noindent  Morbi ac orci et nisl hendrerit mollis. Suspendisse ut massa. Cras nec ante. Pellentesquea nulla. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculusmus. Aliquam tincidunt urna. Nulla ullamcorper vestibulum turpis. Pellentesque cursusluctus mauris. % \noindent makes the rest of the paragraph start without an indent, as if it would actually continue as normal.

\lipsum[2-7]

\end{document}

This is quite dodgy because 1) one has to do everything by hand, which may be very impractical for a long document with plenty of such tables and every time the spacing before the table is changed by any minor editing, it is likely you have to re-place the \linebreak and \noindent; 2) it can not even be done in the place where it is supposed to be --at the end of the page-- but one line above to avoid introducing a blank page.

I'm sure there must be a better way, but no one is giving any better way to do it. So, better having a dodgy workaround than nothing.

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.