5

I am using MiKTeX 2.9 and XeLaTeX. Here is minimal working example:

\documentclass[oneside,final,14pt]{extreport}
\usepackage[top=2.0cm,bottom=2.0cm,left=2.0cm,right=1.0cm]{geometry}
\setlength\parindent{1.5cm}
\usepackage[cm-default]{fontspec}
\usepackage{xunicode}
\usepackage{xltxtra}
\setmainfont[Mapping=tex-text]{Times New Roman}
\setsansfont{Calibri}
\setmonofont{Consolas}
\defaultfontfeatures{Scale=MatchLowercase, Mapping=tex-text}

\usepackage{array}
\usepackage{longtable}
\usepackage{multirow}

\begin{document}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc sagittis pretium felis, id malesuada enim. Nam nunc odio, tempor eu pharetra a, aliquam non dui. Mauris ac vulputate quam. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec euismod lacinia ante, id pretium nulla molestie quis. Duis dignissim massa odio, a cursus arcu ornare nec. Maecenas mollis rhoncus nisl ac luctus. Praesent sollicitudin, arcu ac fringilla semper, massa justo venenatis sapien, eget gravida tellus metus nec ipsum. Praesent convallis consectetur orci, nec placerat dolor tristique nec. Curabitur vel quam et felis luctus interdum. Sed lacinia enim quam, at commodo lorem suscipit a. Nullam posuere nulla mi, nec convallis libero pharetra sed. Aliquam venenatis fringilla sapien eget suscipit. Nulla bibendum consequat lectus, non consequat dui tempus sed.

Nam sed sapien auctor, consectetur augue vel, consectetur nisi. Morbi venenatis massa eget venenatis facilisis. Nullam dapibus nibh eget purus malesuada facilisis. Duis molestie nisl in est posuere mollis. Vestibulum gravida blandit gravida. Cras eu magna posuere, egestas enim vel, auctor nibh. Donec porta interdum lorem ut ornare. Nulla facilisi.

Quisque laoreet, dolor sed gravida posuere, metus nulla sagittis est, vel porttitor justo neque eget lectus. Phasellus quis urna pulvinar, vehicula tortor eget, laoreet lectus. Sed eget mi ut massa egestas venenatis in ac ligula. Nulla eget malesuada purus. Curabitur mollis ligula sit amet urna auctor, nec auctor tellus pellentesque. Maecenas ligula quam, lacinia eu lorem non, malesuada sagittis mauris. Aliquam sapien arcu, aliquet a malesuada eget, accumsan a quam. Donec iaculis auctor elit, non lobortis magna pharetra commodo. Proin convallis neque id libero varius posuere eget eget orci. Aenean sit amet neque non erat pulvinar sodales at ac ligula. Suspendisse potenti. Donec euismod blandit eros, vel imperdiet augue dignissim mattis.

Sed dapibus augue ac felis tincidunt commodo. Quisque ante lacus, condimentum eget justo nec, accumsan vestibulum tellus. Praesent lobortis in dui et vehicula. Nam elit turpis, vehicula consequat lectus in, scelerisque vulputate tortor. Vestibulum ut dolor eu turpis luctus pellentesque at ut risus. Integer et cursus orci, a consectetur metus. Praesent tempus pellentesque diam, sit amet sodales lorem pharetra et. Integer vulputate risus ac ultrices tempus.

Phasellus aliquet gravida eros, at iaculis enim vestibulum at. Sed semper pharetra ipsum, non posuere purus aliquet eu. Mauris bibendum consectetur facilisis. In nec elit pharetra, fringilla elit ut, consequat felis. Maecenas sollicitudin nisi dapibus neque tristique, quis elementum mi posuere. In vestibulum leo a lectus dapibus tincidunt. Quisque in nisl non magna sollicitudin cursus. Praesent sodales rhoncus pulvinar. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Curabitur dapibus egestas suscipit.

\begin{longtable}{|m{3cm}|m{3cm}|m{3cm}|}
\caption{Long long table (for example)}
\label{tab:example}
\\\hline
Lorem ipsum & Dolor sit & Consectetur \\
\endfirsthead
\caption*{Table~\ref{tab:example} (cont.)}
\\\hline
Lorem ipsum & Dolor sit & Consectetur \\
\endhead

\hline
Phasellus & aliquet & gravida \\\hline
eros & at iaculis & enim vestibulum at \\\hline
Sed semper & pharetra ipsum & non posuere \\\hline
\end{longtable}

Morbi in leo non purus dignissim pulvinar a in erat. Donec in lorem non nisl ultricies elementum. Praesent rutrum libero vitae purus suscipit, venenatis convallis neque aliquam.
\end{document}

And this is what I got:

example1 example2

How can I prevent longtable from dividing it in that strange way? The desirable result is to leave the header and the first row on the first page - and if there is no space, to move the whole table to the next page and put next paragraph instead of it.

This is source file, result file and two examples of the correct behavior: example.zip

2
  • Welcome to TeX.SE! Many thanks for posting a complete MWE (minimum working example) that generates the problem behavior you're looking to fix.
    – Mico
    Nov 21, 2013 at 18:51
  • 1
    Just a little advice: You can use \lipsum (while invocing the lipsum package) to produce the example text you used, instead of pasting the whole thing word by word.
    – Ruben
    Nov 21, 2013 at 19:08

1 Answer 1

6

I think you may have a slightly idiosyncratic setup of the table headers that's causing this problem behavior. With something like the code below, I do not get the undesirable page breaking problems you're encountering. Note that the modified code features an \hline statement at the end of both \endfirsthead and \endhead; in contrast, the actual rows of the longtable body no longer start with an \hline instruction.

A separate topic: I would use a \caption (or \caption*) statement in the scope of \endfirsthead but avoid using it in \endhead; I prefer using something like \multicolumn{3}{l}{\em (Table~\ref{tab:example}, cont'd)} as the first row of the \endhead material.

\begin{longtable}{|m{3cm}|m{3cm}|m{3cm}|}
\caption{Long long table (for example)}\label{tab:example} \\ \hline
Lorem ipsum & Dolor sit & Consectetur \\ \hline
\endfirsthead
\multicolumn{3}{l}{\em (Table~\ref{tab:example}, cont'd)} \\ \hline
Lorem ipsum & Dolor sit & Consectetur \\ \hline
\endhead
\hline
\multicolumn{3}{r}{\em (continued on following page)}\\
\endfoot
\hline
\endlastfoot
Phasellus & aliquet & gravida \\ \hline
eros & at iaculis & enim vestibulum at \\ \hline
Sed semper & pharetra ipsum & non posuere \\ \hline
\end{longtable}
4
  • Thank you for your answer! \hline statement in the right position does the trick. By the way, I need \caption* because of special format of all table captions (caption package). Nov 21, 2013 at 19:18
  • @VladimirPanchenko - Let me return the compliment and note that it was your thorough and well-designed MWE that made it straightforward to diagnose and fix the problem.
    – Mico
    Nov 21, 2013 at 19:41
  • hmm does \caption in \endhead really cause problems? (That was the intended design) +1 for sorting out the OP anyway:-) Nov 21, 2013 at 21:50
  • @DavidCarlisle - Thanks for raising this issue; upon rereading what I wrote I think I was a bit too strident. I've rephrased that part of the answer.
    – Mico
    Nov 21, 2013 at 22:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .