# When I use longtable, the table can't fit the whole text, is there any solution? Or is there a suitable way to change the page?

Is there an effective way to automatically display text that cannot be accommodated to the next page?

For example, the code is

\documentclass{article}
\usepackage{longtable,lipsum}
\begin{document}

\begin{longtable}{|l|c|c|c|c|c|}
\hline
\multicolumn{6}{|p{10cm}|}{\lipsum } \\ \hline
\end{longtable}

\end{document}


The compilation result is as follows：

• you are not really using a table at all it is a one row one column table with a p cell so it is just a single \parbox and boxes never break over a page. Feb 15 at 14:17
• if you are looking to frame a text that may break over a page look at tcolorbox (or the older framed or mdframed packages) longtable breaks pages between rows, so in a one-row table can not help. Feb 15 at 14:19
• @David Carlisle Thanks a lot for answering my question so quickly. I actually created the large table, and part of it is a one-row table as you said. It turns out that longtable doesn't break the page. I will try to use \parbox, thanks a lot! Feb 15 at 14:42
• no \parbox is the reason it does not break. Feb 15 at 14:43
• @David Carlisle Sorry, my skills are not very good, I am asking again. I changed the code to the following. \multicolumn{6}{|c|}{\parbox{10cm}{\lipsum}} \\ \hline But still failed to break the page. If it is convenient, would you like to give a sample code? Feb 15 at 15:11

You have to add a \pagebreak from time to time.

\documentclass{article}
\usepackage{longtable,lipsum}
\begin{document}

\begin{longtable}{|l|c|c|c|c|c|}
\hline
\multicolumn{6}{|p{10cm}|}{1. \lipsum[1-4] } \\ \hline
\pagebreak
\hline
\multicolumn{6}{|p{10cm}|}{5. \lipsum[5-8] } \\ \hline
\end{longtable}

\end{document}


With longtable you can run headers and footers that link the partial tables page by page.

\documentclass{article}
\usepackage{longtable,lipsum}

\begin{document}

\begin{longtable}{|l|c|c|c|c|c|}
\hline
\hline

\multicolumn{3}{l} {\footnotesize \emph{ \ldots{} from previous page.}} \\
\hline
\multicolumn{6}{|p{10cm}|}{ \Large Main heading } \\
\hline

\multicolumn{6}{r}{\footnotesize \emph{to be continued in the next page \ldots{} }} \\
\endfoot

\endlastfoot

\multicolumn{6}{|p{10cm}|}{1. \lipsum[1-4] } \\ \hline
\pagebreak
\multicolumn{6}{|p{10cm}|}{5. \lipsum[5-8] } \\ \hline
\end{longtable}

\end{document}

• Thank you for your answer and the specific code! It was very useful for me. Feb 15 at 17:16