3

How can I prevent this table from going off the page please? I need solution for both vertical overflowing and horizontal overflowing

  1. For horizontal, it exceeds the page on the right side. How to limit and scale it so that it fit the page width. See MWE 1
  2. For vertical, the table does not break and continue of the next page. It just stops at the very bottom of the first page and is incomplete. See MWE 2
  3. MWE 3 has both types of overflow. Basically, I want to scale the table to linewidth, and let it continue on next page.

Thank you in advance

Here is my MWE 1 for horizontal overflowing

 \documentclass{article}

\begin{document}

\begin{table}
\centering
\caption{Relationship of the lesson with the ARCS model}
\begin{tabular}{|l|l|} 
\hline
\textbf{Attention}    & Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus dignissim molestie massa, ac mattis massa varius nec. Morbi vitae ullamcorper est. Phasellus mollis tristique ipsum sed ullamcorper. Nulla vel venenatis tellus. In hac habitasse platea dictumst. Donec pretium metus sit amet erat tristique, non mollis velit pharetra.~  \\ 
\hline
\textbf{Relevance}    & Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus dignissim molestie massa, ac mattis massa varius nec. Morbi vitae ullamcorper est. Phasellus mollis tristique ipsum sed ullamcorper. Nulla vel venenatis tellus. In hac habitasse platea dictumst. Donec pretium metus sit amet erat tristique, non mollis velit pharetra.~  \\ 
\hline
\textbf{Confidence}   & Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus dignissim molestie massa, ac mattis massa varius nec. Morbi vitae ullamcorper est. Phasellus mollis tristique ipsum sed ullamcorper. Nulla vel venenatis tellus. In hac habitasse platea dictumst. Donec pretium metus sit amet erat tristique, non mollis velit pharetra.~  \\ 
\hline
\textbf{Satisfaction} & Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus dignissim molestie massa, ac mattis massa varius nec. Morbi vitae ullamcorper est. Phasellus mollis tristique ipsum sed ullamcorper. Nulla vel venenatis tellus. In hac habitasse platea dictumst. Donec pretium metus sit amet erat tristique, non mollis velit pharetra.~  \\
\hline
\end{tabular}
\end{table}
\end{document}

Here is my MWE 2 for vertical overflowing

\documentclass{article}

\begin{document}

\begin{table}
\centering
\begin{tabular}{|p{3cm}|p{8cm}|} 
\hline
Test 1 & Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus dignissim molestie massa, ac mattis massa varius nec. Morbi vitae ullamcorper est. Phasellus mollis tristique ipsum sed ullamcorper. Nulla vel venenatis tellus. In hac habitasse platea dictumst. Donec pretium metus sit amet erat tristique, non mollis velit pharetra. Suspendisse maximus nunc quis arcu auctor, a auctor nunc faucibus. Quisque id lorem ut mauris imperdiet facilisis. Ut interdum, mauris vitae molestie venenatis, turpis turpis varius felis, eget imperdiet leo nulla laoreet tortor. Donec vel mi quam. Phasellus tincidunt quam in nisl elementum porta. Mauris a augue nisl. Proin viverra feugiat augue, nec.  \\ 
\hline
Test 2 & Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus dignissim molestie massa, ac mattis massa varius nec. Morbi vitae ullamcorper est. Phasellus mollis tristique ipsum sed ullamcorper. Nulla vel venenatis tellus. In hac habitasse platea dictumst. Donec pretium metus sit amet erat tristique, non mollis velit pharetra. Suspendisse maximus nunc quis arcu auctor, a auctor nunc faucibus. Quisque id lorem ut mauris imperdiet facilisis. Ut interdum, mauris vitae molestie venenatis, turpis turpis varius felis, eget imperdiet leo nulla laoreet tortor. Donec vel mi quam. Phasellus tincidunt quam in nisl elementum porta. Mauris a augue nisl. Proin viverra feugiat augue, nec.  \\ 
\hline
Test 3 & Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus dignissim molestie massa, ac mattis massa varius nec. Morbi vitae ullamcorper est. Phasellus mollis tristique ipsum sed ullamcorper. Nulla vel venenatis tellus. In hac habitasse platea dictumst. Donec pretium metus sit amet erat tristique, non mollis velit pharetra. Suspendisse maximus nunc quis arcu auctor, a auctor nunc faucibus. Quisque id lorem ut mauris imperdiet facilisis. Ut interdum, mauris vitae molestie venenatis, turpis turpis varius felis, eget imperdiet leo nulla laoreet tortor. Donec vel mi quam. Phasellus tincidunt quam in nisl elementum porta. Mauris a augue nisl. Proin viverra feugiat augue, nec.  \\ 
\hline
Test 4 & Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus dignissim molestie massa, ac mattis massa varius nec. Morbi vitae ullamcorper est. Phasellus mollis tristique ipsum sed ullamcorper. Nulla vel venenatis tellus. In hac habitasse platea dictumst. Donec pretium metus sit amet erat tristique, non mollis velit pharetra. Suspendisse maximus nunc quis arcu auctor, a auctor nunc faucibus. Quisque id lorem ut mauris imperdiet facilisis. Ut interdum, mauris vitae molestie venenatis, turpis turpis varius felis, eget imperdiet leo nulla laoreet tortor. Donec vel mi quam. Phasellus tincidunt quam in nisl elementum porta. Mauris a augue nisl. Proin viverra feugiat augue, nec.  \\ 
\hline
Test 5 & Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus dignissim molestie massa, ac mattis massa varius nec. Morbi vitae ullamcorper est. Phasellus mollis tristique ipsum sed ullamcorper. Nulla vel venenatis tellus. In hac habitasse platea dictumst. Donec pretium metus sit amet erat tristique, non mollis velit pharetra. Suspendisse maximus nunc quis arcu auctor, a auctor nunc faucibus. Quisque id lorem ut mauris imperdiet facilisis. Ut interdum, mauris vitae molestie venenatis, turpis turpis varius felis, eget imperdiet leo nulla laoreet tortor. Donec vel mi quam. Phasellus tincidunt quam in nisl elementum porta. Mauris a augue nisl. Proin viverra feugiat augue, nec.  \\ 
\hline
Test 6 & Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus dignissim molestie massa, ac mattis massa varius nec. Morbi vitae ullamcorper est. Phasellus mollis tristique ipsum sed ullamcorper. Nulla vel venenatis tellus. In hac habitasse platea dictumst. Donec pretium metus sit amet erat tristique, non mollis velit pharetra. Suspendisse maximus nunc quis arcu auctor, a auctor nunc faucibus. Quisque id lorem ut mauris imperdiet facilisis. Ut interdum, mauris vitae molestie venenatis, turpis turpis varius felis, eget imperdiet leo nulla laoreet tortor. Donec vel mi quam. Phasellus tincidunt quam in nisl elementum porta. Mauris a augue nisl. Proin viverra feugiat augue, nec.  \\ 
\hline
Test 7 & Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus dignissim molestie massa, ac mattis massa varius nec. Morbi vitae ullamcorper est. Phasellus mollis tristique ipsum sed ullamcorper. Nulla vel venenatis tellus. In hac habitasse platea dictumst. Donec pretium metus sit amet erat tristique, non mollis velit pharetra. Suspendisse maximus nunc quis arcu auctor, a auctor nunc faucibus. Quisque id lorem ut mauris imperdiet facilisis. Ut interdum, mauris vitae molestie venenatis, turpis turpis varius felis, eget imperdiet leo nulla laoreet tortor. Donec vel mi quam. Phasellus tincidunt quam in nisl elementum porta. Mauris a augue nisl. Proin viverra feugiat augue, nec.  \\
\hline
\end{tabular}
\end{table}
\end{document}

MWE 3 needing horizontal scaling and flow to next page

\documentclass{article}
\usepackage{multirow}

\begin{document}

\begin{table}
\centering
\begin{tabular}{|l|l|l|l|} 
\hline
\multirow{3}{*}{Suspendisse maximus} & Mauris~                   & \multicolumn{2}{l|}{Nulla vel venenatis tellus. In hac habitasse platea dictumst. Donec pretium metus sit amet erat tristique, non mollis velit pharetra.}                                                                                                                                                                                                                                  \\ 
\cline{2-4}
                                     & feugiat~                  & \multicolumn{2}{l|}{Nulla vel venenatis tellus. In hac habitasse platea dictumst. Donec pretium metus sit amet erat tristique, non mollis velit pharetra.}                                                                                                                                                                                                                                  \\ 
\cline{2-4}
                                     & Mauris~                   & \multicolumn{2}{l|}{Nulla vel venenatis tellus. In hac habitasse platea dictumst. Donec pretium metus sit amet erat tristique, non mollis velit pharetra.}                                                                                                                                                                                                                                  \\ 
\hline
\multirow{3}{*}{Suspendisse maximus} & feugiat~                  & \multicolumn{2}{l|}{Nulla vel venenatis tellus. In hac habitasse platea dictumst. Donec pretium metus sit amet erat tristique, non mollis velit pharetra.}                                                                                                                                                                                                                                  \\ 
\cline{2-4}
                                     & feugiat~                  & \multicolumn{2}{l|}{Nulla vel venenatis tellus. In hac habitasse platea dictumst. Donec pretium metus sit amet erat tristique, non mollis velit pharetra.}                                                                                                                                                                                                                                  \\ 
\cline{2-4}
                                     & Mauris~                   & \multicolumn{2}{l|}{Nulla vel venenatis tellus. In hac habitasse platea dictumst. Donec pretium metus sit amet erat tristique, non mollis velit pharetra.}                                                                                                                                                                                                                                  \\ 
\hline
\multirow{9}{*}{Suspendisse maximus} & \multirow{3}{*}{Mauris~}  & habitasse~ & \begin{tabular}[c]{@{}l@{}}\begin{tabular}{@{\labelitemi\hspace{\dimexpr\labelsep+0.5\tabcolsep}}l}Ut interdum, mauris vitae molestie venenatis, \\turpis turpis varius felis, eget imperdiet leo nulla laoreet tortor. \\Donec vel mi quam. Phasellus tincidunt quam in nisl elementum \\porta. Mauris a augue nisl. Proin viverra feugiat~ ~\end{tabular}\end{tabular}       \\ 
\cline{3-4}
                                     &                           & venenatis~ & \begin{tabular}[c]{@{}l@{}}\begin{tabular}{@{\labelitemi\hspace{\dimexpr\labelsep+0.5\tabcolsep}}l}Ut interdum, mauris vitae molestie venenatis,\\turpis turpis varius felis, eget imperdiet leo nulla laoreet tortor.\\Donec vel mi quam. Phasellus tincidunt quam in nisl elementum\\porta. Mauris a augue nisl. Proin viverra feugiat~ ~\end{tabular}\end{tabular}          \\ 
\cline{3-4}
                                     &                           & dictumst   & \begin{tabular}[c]{@{}l@{}}\begin{tabular}{@{\labelitemi\hspace{\dimexpr\labelsep+0.5\tabcolsep}}l}Ut interdum, mauris vitae molestie venenatis,\\turpis turpis varius felis, eget imperdiet leo nulla laoreet tortor.\\Donec vel mi quam. Phasellus tincidunt quam in nisl elementum\\porta. Mauris a augue nisl. Proin viverra feugiat~ ~\end{tabular}\end{tabular}          \\ 
\cline{2-4}
                                     & \multirow{3}{*}{feugiat~} & venenatis~ & \begin{tabular}[c]{@{}l@{}}\begin{tabular}{@{\labelitemi\hspace{\dimexpr\labelsep+0.5\tabcolsep}}l}Ut interdum, mauris vitae molestie venenatis,\\turpis turpis varius felis, eget imperdiet leo nulla laoreet tortor.\\Donec vel mi quam. Phasellus tincidunt quam in nisl elementum\\porta. Mauris a augue nisl. Proin viverra feugiat~ ~\end{tabular}\end{tabular}          \\ 
\cline{3-4}
                                     &                           & dictumst   & \begin{tabular}[c]{@{}l@{}}\begin{tabular}{@{\labelitemi\hspace{\dimexpr\labelsep+0.5\tabcolsep}}l}Ut interdum, mauris vitae molestie venenatis,\\turpis turpis varius felis, eget imperdiet leo nulla laoreet tortor.\\Donec vel mi quam. Phasellus tincidunt quam in nisl elementum\\porta. Mauris a augue nisl. Proin viverra feugiat~ ~\end{tabular}\end{tabular}          \\ 
\cline{3-4}
                                     &                           & habitasse~ & \begin{tabular}[c]{@{}l@{}}\begin{tabular}{@{\labelitemi\hspace{\dimexpr\labelsep+0.5\tabcolsep}}l}Ut interdum, mauris vitae molestie venenatis,\\turpis turpis varius felis, eget imperdiet leo nulla laoreet tortor.\\Donec vel mi quam. Phasellus tincidunt quam in nisl elementum\\porta. Mauris a augue nisl. Proin viverra feugiat~ ~\end{tabular}\end{tabular}          \\ 
\cline{2-4}
                                     & \multirow{3}{*}{Mauris~}  & dictumst   & \begin{tabular}[c]{@{}l@{}}\begin{tabular}{@{\labelitemi\hspace{\dimexpr\labelsep+0.5\tabcolsep}}l}Ut interdum, mauris vitae molestie venenatis,\\turpis turpis varius felis, eget imperdiet leo nulla laoreet tortor.\\Donec vel mi quam. Phasellus tincidunt quam in nisl elementum\\porta. Mauris a augue nisl. Proin viverra feugiat~ ~\end{tabular}\end{tabular}          \\ 
\cline{3-4}
                                     &                           & habitasse~ & \begin{tabular}[c]{@{}l@{}}\begin{tabular}{@{\labelitemi\hspace{\dimexpr\labelsep+0.5\tabcolsep}}l}Ut interdum, mauris vitae molestie venenatis,\\turpis turpis varius felis, eget imperdiet leo nulla laoreet tortor.\\Donec vel mi quam. Phasellus tincidunt quam in nisl elementum\\porta. Mauris a augue nisl. Proin viverra feugiat~ ~\end{tabular}\end{tabular}          \\ 
\cline{3-4}
                                     &                           & dictumst   & \begin{tabular}[c]{@{}l@{}}\begin{tabular}{@{\labelitemi\hspace{\dimexpr\labelsep+0.5\tabcolsep}}l}Ut interdum, mauris vitae molestie venenatis,\\turpis turpis varius felis, eget imperdiet leo nulla laoreet tortor.\\Donec vel mi quam. Phasellus tincidunt quam in nisl elementum\\porta. Mauris a augue nisl. Proin viverra feugiat~ ~\end{tabular}\end{tabular}          \\ 
\hline
Suspendisse maximus                  & habitasse~                & \multicolumn{2}{l|}{Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus dignissim molestie massa, ac mattis massa varius nec. Morbi vitae ullamcorper est. Phasellus mollis tristique ipsum sed ullamcorper. Nulla vel venenatis tellus.~}                                                                                                                                   \\ 
\hline
Suspendisse maximus                  & habitasse~ ~ ~            & \multicolumn{2}{l|}{Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus dignissim molestie massa, ac mattis massa varius nec. Morbi vitae ullamcorper est. Phasellus mollis tristique ipsum sed ullamcorper. Nulla vel venenatis tellus.~ ~ ~}                                                                                                                               \\ 
\hline
Suspendisse maximus                  & habitasse~ ~ ~            & \multicolumn{2}{l|}{Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus dignissim molestie massa, ac mattis massa varius nec. Morbi vitae ullamcorper est. Phasellus mollis tristique ipsum sed ullamcorper. Nulla vel venenatis tellus.~ ~ ~}                                                                                                                               \\ 
\hline
Suspendisse maximus                  & habitasse~ ~ ~            & \multicolumn{2}{l|}{Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus dignissim molestie massa, ac mattis massa varius nec. Morbi vitae ullamcorper est. Phasellus mollis tristique ipsum sed ullamcorper. Nulla vel venenatis tellus.~ ~ ~}                                                                                                                               \\ 
\hline
                                     &                           & \multicolumn{2}{l|}{\begin{tabular}[c]{@{}l@{}}\begin{tabular}{@{\labelitemi\hspace{\dimexpr\labelsep+0.5\tabcolsep}}l}Ut interdum, mauris vitae molestie venenatis,\\turpis turpis varius felis, eget imperdiet leo nulla laoreet tortor.\\Donec vel mi quam. Phasellus tincidunt quam in nisl elementum\\porta. Mauris a augue nisl. Proin viverra feugiat~ ~\end{tabular}\end{tabular}}  \\
\hline
\end{tabular}
\end{table}
\end{document}
  • What do you want to do with the text? Do you want to have a line break, in what section of the text? – manooooh Mar 21 at 10:08
  • When adding an example you should add enough code to make it compilable – Raven Mar 21 at 10:25
  • Updated the MWE. Thanks – Nadeem Muhammad Mar 21 at 12:28
3

Assuming that by "going off the page" you mean overflowing the page margin instead of adding a line break, you can fix the problem by using the p (Paragraph) column type that takes a width argument:

\documentclass{article}

\begin{document}
    \begin{table}
    \centering
    \caption{Relationship of the lesson with the ARCS model}
    \begin{tabular}{|p{3cm}|p{8cm}|} 
    \hline
    \textbf{Attention}    & Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus dignissim molestie massa, ac mattis massa varius nec. Morbi vitae ullamcorper est. Phasellus mollis tristique ipsum sed ullamcorper. Nulla vel venenatis tellus. In hac habitasse platea dictumst. Donec pretium metus sit amet erat tristique, non mollis velit pharetra.~  \\ 
    \hline
    \textbf{Relevance}    & Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus dignissim molestie massa, ac mattis massa varius nec. Morbi vitae ullamcorper est. Phasellus mollis tristique ipsum sed ullamcorper. Nulla vel venenatis tellus. In hac habitasse platea dictumst. Donec pretium metus sit amet erat tristique, non mollis velit pharetra.~  \\ 
    \hline
    \textbf{Confidence}   & Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus dignissim molestie massa, ac mattis massa varius nec. Morbi vitae ullamcorper est. Phasellus mollis tristique ipsum sed ullamcorper. Nulla vel venenatis tellus. In hac habitasse platea dictumst. Donec pretium metus sit amet erat tristique, non mollis velit pharetra.~  \\ 
    \hline
    \textbf{Satisfaction} & Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus dignissim molestie massa, ac mattis massa varius nec. Morbi vitae ullamcorper est. Phasellus mollis tristique ipsum sed ullamcorper. Nulla vel venenatis tellus. In hac habitasse platea dictumst. Donec pretium metus sit amet erat tristique, non mollis velit pharetra.~  \\
    \hline
    \end{tabular}
    \end{table}
\end{document}

enter image description here

  • This works. Thanks. Now how do I center the Attention, Relevance etc. in the middle of the cell? – Nadeem Muhammad Mar 21 at 14:11
  • I have added another question concerning vertical overflow, can you help ? – Nadeem Muhammad Mar 21 at 14:32
  • @NadeemMuhammad: If you want your table to automatically be continued on a second page, you will need the longtable package. – leandriis Mar 21 at 14:43
  • 1
    @NadeemMuhammad it is really bad practice to edit your question to include new questions after an answer has been made that covers the original question. In the future, please create a new question for that. Apart from that leandriis is right: If you want your table to continue on another page you need a longtable. For centering you can add \newcolumntype{P}[1]{>{\centering\arraybackslash}p{#1}} after also having \usepackage{array} and then use the Pcolumn type instead of the p one – Raven Mar 21 at 16:41
  • 1
    i took liberty and add picture of table generated by suggested solution. – Zarko Mar 21 at 17:17
3

i would use tabularx table environment:

\documentclass{article}
\usepackage{tabularx}

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

\begin{document}
\begin{table}
\centering
\caption{Relationship of the lesson with the ARCS model}
\begin{tabularx}{\linewidth}{|>{\bfseries}l|X|}
    \hline
Attention       & Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus dignissim molestie massa, ac mattis massa varius nec. Morbi vitae ullamcorper est. Phasellus mollis tristique ipsum sed ullamcorper. Nulla vel venenatis tellus. In hac habitasse platea dictumst. Donec pretium metus sit amet erat tristique, non mollis velit pharetra.  \\
    \hline
Relevance       & Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus dignissim molestie massa, ac mattis massa varius nec. Morbi vitae ullamcorper est. Phasellus mollis tristique ipsum sed ullamcorper. Nulla vel venenatis tellus. In hac habitasse platea dictumst. Donec pretium metus sit amet erat tristique, non mollis velit pharetra.  \\
    \hline
Confidence      & Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus dignissim molestie massa, ac mattis massa varius nec. Morbi vitae ullamcorper est. Phasellus mollis tristique ipsum sed ullamcorper. Nulla vel venenatis tellus. In hac habitasse platea dictumst. Donec pretium metus sit amet erat tristique, non mollis velit pharetra.  \\
    \hline
Satisfaction    & Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus dignissim molestie massa, ac mattis massa varius nec. Morbi vitae ullamcorper est. Phasellus mollis tristique ipsum sed ullamcorper. Nulla vel venenatis tellus. In hac habitasse platea dictumst. Donec pretium metus sit amet erat tristique, non mollis velit pharetra.  \\
    \hline
\end{tabularx}
    \end{table}
\end{document}

which gives

enter image description here

(red lines indicate text borders).

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.