0

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: enter image description here

5
  • 3
    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
  • 1
    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!
    – ms ms
    Feb 15 at 14:42
  • 2
    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?
    – ms ms
    Feb 15 at 15:11
0

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

x

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

b

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

\begin{document}

\begin{longtable}{|l|c|c|c|c|c|}        
    \hline      
    \multicolumn{6}{|p{10cm}|}{\Large Main heading } \\ 
    \hline
    \endfirsthead
    
    \multicolumn{3}{l} {\footnotesize \emph{ \ldots{} from previous page.}} \\
    \hline
    \multicolumn{6}{|p{10cm}|}{ \Large Main heading } \\ 
    \hline
    \endhead
    
    \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}
1
  • Thank you for your answer and the specific code! It was very useful for me.
    – ms ms
    Feb 15 at 17:16

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.