1

I find that the following code makes the indicated text float around outside of the table. Why is this?

Note that the code uses a custom cls file (companyname_sop); however, the same problem occurs if you use the article class file too.

\documentclass[11pt]{companyname_sop} %This is a custom cls file that applies formatting to the doc
\usepackage{hyperref}
\usepackage{pdfpages}
\usepackage{multirow}
\usepackage{threeparttable}
\usepackage{longtable}
\usepackage{float}
\usepackage{fancyhdr}
\title{Name of Doc}
\doctype{Name of Doc Type}
\docnumber{12-34567}
\supercedes{None}
\effectivedate{09/26/16}
\revisiondate{09/26/16}
\begin{document}
\begin{longtable}{|p{4cm}|p{.25cm}|p{.25cm}|p{11.5cm}|}
\caption{Title of Table} \label{t:label_of_table}
\endfirsthead
\multicolumn{4}{c} {{\bfseries \tablename\ \thetable{} -- Continued from Previous Page }} \\ \hline 
\endhead
\hline \multicolumn{4}{|r|}{Continued on Next Page} \\ \hline
\endfoot
\hline \hline
\endlastfoot 
\hline \fancyhead{}
\multirow{6}{\linewidth}{A line in the first column, which is meant to cover seven rows in the fourth column}  & \multirow{6}{\linewidth}{A} & 1 & A much longer line than before, which forces the document to break over multiple pages, showing the problem, which is that the text in the first column floats outside the table when the table breaks over multiple pages \\ \cline{3-4}
                   &                   & 2 & A much longer line than before, which forces the document to break over multiple pages, showing the problem, which is that the text in the first column floats outside the table when the table breaks over multiple pages \\ \cline{3-4}
                   &                   & 3 & A much longer line than before, which forces the document to break over multiple pages, showing the problem, which is that the text in the first column floats outside the table when the table breaks over multiple pages \\ \cline{3-4}
                   &                   & 4 & A much longer line than before, which forces the document to break over multiple pages, showing the problem, which is that the text in the first column floats outside the table when the table breaks over multiple pages \\ \cline{3-4}
                   &                   & 5 & A much longer line than before, which forces the document to break over multiple pages, showing the problem, which is that the text in the first column floats outside the table when the table breaks over multiple pages \\ \cline{3-4}                   &                   & 6 & A much longer line than before, which forces the document to break over multiple pages, showing the problem, which is that the text in the first column floats outside the table when the table breaks over multiple pages \\ \cline{3-4}
 &  & 7 & A much longer line than before, which forces the document to break over multiple pages, showing the problem, which is that the text in the first column floats outside the table when the table breaks over multiple pages; however, it only shows when it's long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long in the penultimate row, so that only one row of the next section of the table shows up on the same page as the preceding rows           \\    \hline
\multirow{8}{\linewidth}{Line one of this line \newline Second line of this line}  & \multirow{8}{\linewidth}{B} & 1 & A much longer line than before, which forces the document to break over multiple pages, showing the problem, which is that the text in the first column floats outside the table when the table breaks over multiple pages \\ \cline{3-4}
                   &                   & 2 & A much longer line than before, which forces the document to break over multiple pages, showing the problem, which is that the text in the first column floats outside the table when the table breaks over multiple pages \\ \cline{3-4}
                   &                   & 3 & A much longer line than before, which forces the document to break over multiple pages, showing the problem, which is that the text in the first column floats outside the table when the table breaks over multiple pages \\ \cline{3-4}
                   &                   & 4 & A much longer line than before, which forces the document to break over multiple pages, showing the problem, which is that the text in the first column floats outside the table when the table breaks over multiple pages \\ \cline{3-4}
                   &                   & 5 & A much longer line than before, which forces the document to break over multiple pages, showing the problem, which is that the text in the first column floats outside the table when the table breaks over multiple pages \\ \cline{3-4}
                   &                   & 6 & A much longer line than before, which forces the document to break over multiple pages, showing the problem, which is that the text in the first column floats outside the table when the table breaks over multiple pages
 \\ \cline{3-4}
                   &                   & 7 & A much longer line than before, which forces the document to break over multiple pages, showing the problem, which is that the text in the first column floats outside the table when the table breaks over multiple pages \\ \cline{3-4}
                   &                   & 8 & A line \\ \hline
\multirow{8}{\linewidth}{This floats outside the table cells, at the level of the footer}  & \multirow{8}{\linewidth}{This does too} & 1 & A line \\* \cline{3-4}
                   &                   & 2 & A line \\ \cline{3-4}
                   &                   & 3 & A line \\ \cline{3-4}
                   &                   & 4 & A line \\ \cline{3-4}
                   &                   & 5 & A line \\ \cline{3-4}                 
                   &                   & 6 & A line \\ \cline{2-4}
                   &                   & 7 & Another line \\ \cline{2-4}
                   &                   & 8 & Another line again \\ \hline
                   & D &  & Yet another line \\ \hline

\end{longtable}
\begin{tablenotes}
\item *Here is a footnote.
\end{tablenotes}
    \end{document}
  • Apologies for the lack of line breaks; when I try to insert them in the code above for clarity, StackExchange seems to double the number of lines I want to add & box some of them (but not others) with grey highlighting, so it detracts from the clarity more than it adds to it. – andrew Jun 27 '18 at 22:18
  • Could you please provide a link to the companyname_sop.cls file so that we can compile the file? Also, to format as code you select the text and click the {} button at the top of the edit window. – Phelype Oleinik Jun 27 '18 at 22:19
  • 3
    it would be best if you could check you can get the same problem with article class and if so use that to save people downloading your custom class. If the problem only occurs with the custom class that is useful information to help someone debug – David Carlisle Jun 27 '18 at 22:21
  • if you must use \multirow in longtable (it is best to avoid it) then you need to use \\* not \\ to end the rows otherwise you may get a page break in teh rows that are being spanned. – David Carlisle Jun 27 '18 at 22:23
  • Thanks folks; I tried adding * to the row breaks (I use //, not \\ as in the comment, to end rows, so I made it //*; let me know if this makes a difference), but it still doesn't work; I have posted the code for the cls file. Thanks for the notes. – andrew Jun 27 '18 at 22:46
2

see, if the following code is useful to you. in it i change column widths so, that the table fit to text width and that cells' contents has enough space:

\documentclass[11pt]{article}
\usepackage[margin=20mm]{geometry}

\usepackage{makecell}
\setcellgapes{3pt}
\usepackage{multirow}
\usepackage{longtable}
\usepackage{threeparttable}

%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%

\begin{document}
\begingroup
\makegapedcells
    \begin{longtable}{| p{\dimexpr4.0cm-1.25\tabcolsep-\arrayrulewidth}|
                        p{\dimexpr1.0cm-1.25\tabcolsep-\arrayrulewidth}|
                        p{\dimexpr0.5cm-1.25\tabcolsep-\arrayrulewidth}|
                        p{\dimexpr11.5cm-1.25\tabcolsep-\arrayrulewidth}|}
\caption{Title of Table}
\label{t:label_of_table}                    \\
    \hline
\endfirsthead
\caption{-- Continued from Previous Page}   \\
    \hline
\endhead
    \hline
\multicolumn{4}{r}{\textit{Continued on Next Page}}
\endfoot
    \hline
\endlastfoot
\multirow[t]{6}{=}{A line in the first column, which is meant to cover seven rows in the fourth column}
    & \multirow[t]{6}{=}{A} & 1 & A much longer line than before, which forces the document to break over multiple pages, showing the problem, which is that the text in the first column floats outside the table when the table breaks over multiple pages \\*
    \cline{3-4}
    &   & 2 & A much longer line than before, which forces the document to break over multiple pages, showing the problem, which is that the text in the first column floats outside the table when the table breaks over multiple pages \\*
    \cline{3-4}
    &   & 3 & A much longer line than before, which forces the document to break over multiple pages, showing the problem, which is that the text in the first column floats outside the table when the table breaks over multiple pages \\*
    \cline{3-4}
    &   & 4 & A much longer line than before, which forces the document to break over multiple pages, showing the problem, which is that the text in the first column floats outside the table when the table breaks over multiple pages \\*
    \cline{3-4}
    &   & 5 & A much longer line than before, which forces the document to break over multiple pages, showing the problem, which is that the text in the first column floats outside the table when the table breaks over multiple pages \\*
    \cline{3-4}
    &   & 6 & A much longer line than before, which forces the document to break over multiple pages, showing the problem, which is that the text in the first column floats outside the table when the table breaks over multiple pages \\*
    \cline{3-4}
    &  & 7 & A much longer line than before, which forces the document to break over multiple pages, showing the problem, which is that the text in the first column floats outside the table when the table breaks over multiple pages; however, it only shows when it's long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long, long in the penultimate row, so that only one row of the next section of the table shows up on the same page as the preceding rows                               \\
    \hline
    \newpage
\multirow[t]{8}{=}{Line one of this line \newline Second line of this line}
    & \multirow[t]{8}{=}{B} & 1 & A much longer line than before, which forces the document to break over multiple pages, showing the problem, which is that the text in the first column floats outside the table when the table breaks over multiple pages \\*
    \cline{3-4}
    &   & 2 & A much longer line than before, which forces the document to break over multiple pages, showing the problem, which is that the text in the first column floats outside the table when the table breaks over multiple pages \\*
    \cline{3-4}
    &   & 3 & A much longer line than before, which forces the document to break over multiple pages, showing the problem, which is that the text in the first column floats outside the table when the table breaks over multiple pages \\
    \cline{3-4}
    &   & 4 & A much longer line than before, which forces the document to break over multiple pages, showing the problem, which is that the text in the first column floats outside the table when the table breaks over multiple pages \\
    \cline{3-4}
    &   & 5 & A much longer line than before, which forces the document to break over multiple pages, showing the problem, which is that the text in the first column floats outside the table when the table breaks over multiple pages \\
    \cline{3-4}
    &   & 6 & A much longer line than before, which forces the document to break over multiple pages, showing the problem, which is that the text in the first column floats outside the table when the table breaks over multiple pages \\
    \cline{3-4}
    &   & 7 & A much longer line than before, which forces the document to break over multiple pages, showing the problem, which is that the text in the first column floats outside the table when the table breaks over multiple pages \\
    \cline{3-4}
    &   & 8 & A line \\
    \hline
\multirow[t]{8}{\linewidth}{This floats outside the table cells, at the level of the footer}
    & \multirow[t]{8}{\linewidth}{This does too} & 1 & A line \\ \cline{3-4}
    &   & 2 & A line        \\ \cline{3-4}
    &   & 3 & A line        \\ \cline{3-4}
    &   & 4 & A line        \\ \cline{3-4}
    &   & 5 & A line        \\ \cline{3-4}
    &   & 6 & A line        \\ \cline{3-4}
    &   & 7 & Another line  \\ \cline{2-4}
    &   & 8 & Another line  \\ \cline{2-4}
    & D & 9 & Yet another line  \\ \cline{2-4}
\end{longtable}
\begin{tablenotes}
\item *Here is a footnote.
\end{tablenotes}
\endgroup
\end{document}

it contain manual tweaking of page break.

  • Wow--well done, Zarko! That seems to have done it. Thanks for the wizardry! – andrew Jun 28 '18 at 22:42

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.