2

I have a simple table, but is really long and I want it to be split in the next page. The code is like that:

\begin{table}[H]
\centering
\begin{tabular}{|c|c|}
IDs &  pairs used \\
\hline
aa\\
aa\\
aa\\
aa\\
aa\\
aa\\
...........
    \end{tabular}
    \caption{List of DTMs}
    \label{tab:abc}
    \end{table}

How do I split this long table? I inserted:

\usepackage{longtable} 
3

enter image description here

\documentclass{article}
%\usepackage[table]{xcolor}
\usepackage{multirow,longtable}
\begin{document}

\begin{longtable}{cc}
\hline
ID & Pair Used \\
\hline
\endhead

\hline
\endlastfoot

a & b\\
a1 & b1\\

\end{longtable}

\end{document}

To place the caption at the bottom of the longtable

enter image description here

\documentclass{article}
%\usepackage[table]{xcolor}
\usepackage{longtable}
\begin{document}

\begin{longtable}{cc}
\hline
ID & Pair Used \\
\hline
\endhead

\hline
\caption{text}
\endlastfoot

a & b\\
a1 & b1\\

\end{longtable}

\end{document}
4
  • I have 150 IDs in the table. I inserted the same codes you sent but still, it does not split to the next page. – PlanetaryGeo Aug 4 '20 at 14:49
  • 2
    Do not place a longtable inside of a table. A tablecan not be broken over multiple pages, thus surrounding longtable with table prevents the page-breaking behaviour of longtable entirely. – leandriis Aug 4 '20 at 14:51
  • Oh Yes! Thank you very much! – PlanetaryGeo Aug 4 '20 at 14:58
  • 2
    I've taken the liberty of editing some of code in the second example. Feel free to revert. – Mico Aug 4 '20 at 15:13
2

Edit

I have changed the table slightly to make you see how well it breaks over multiple pages:

\documentclass{article}
\usepackage[utf8]{inputenc}

\usepackage{longtable,booktabs}

\begin{document}

\begin{longtable}{c|c}
\toprule
IDs & pairs used \\
\midrule\endhead
aa &\\
aa &\\
aa &\\
aa &\\
aa &\\
aa &\\
aa &\\
aa &\\
aa &\\
aa &\\
aa &\\
aa &\\
aa &\\
aa &\\
aa &\\
aa &\\
aa &\\
aa &\\
aa &\\
aa &\\
aa &\\
aa &\\
aa &\\
aa &\\
aa &\\
aa &\\
aa &\\
aa &\\
aa &\\
aa &\\
aa &\\
aa &\\
aa &\\
aa &\\
aa &\\
aa &\\
aa &\\
aa &\\
aa &\\
aa &\\
aa &\\
aa &\\
aa &\\
aa &\\
aa &\\
aa &\\
aa &\\
aa &\\
aa &\\
aa &\\
aa &\\
aa &\\
aa &\\
aa &\\
aa &\\
........... & ........... \\
\bottomrule
\caption{List of DTMs} \label{tab:abc} \\
\end{longtable}

\end{document}

Visual here:

No matter how long the table gets it breaks over to the next page

With tables it always depends how much information they should store. If they are text heavy, you need to do something in the neighborhood of the following solution. If you want to split the table at an arbitrary point (see the \newpage-command), you could try this:

\documentclass{article}
\usepackage[utf8]{inputenc}

\usepackage{longtable,array,booktabs}
\usepackage{blindtext}

\begin{document}

\begin{longtable}{>{\centering\arraybackslash}p{.45\textwidth}>{\centering\arraybackslash}p{.45\textwidth}}
\caption{List of DTMs} \label{tab:abc} \\
\toprule
IDs & pairs used \\
\midrule
\blindtext[1] & \blindtext[1]\\
aa &\\
aa &\\\newpage
aa &\\
aa &\\
aa &\\
........... & ........... \\
\bottomrule
\end{longtable}

\end{document}

And here is the visual:

Table with page break.

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.