为什么单元格文本浮动在表格外面?

为什么单元格文本浮动在表格外面?

我发现以下代码使指示的文本浮动在表格之外。这是为什么?

请注意,代码使用自定义 cls 文件(companyname_sop);但是,如果您也使用 article 类文件,也会出现同样的问题。

\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}

答案1

看看下面的代码是否对你有用。在其中我更改列宽,以便表格适合文本宽度并且单元格的内容有足够的空间:

\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}

它包含分页符的手动调整。

相关内容