How to split a table into multiple pages in LaTeX?
In this tutorial, you will learn how to split a table into multiple pages in LaTeX.
Usually, I create tables using the tabular environment, but when I want my table will break when the page ends and automatically appear on the next page, the rest of the table.
In this case, you must use the longtable environment other than the tabular.
Table span multiple pages in LaTeX
In order to use the longtable environment first, you have to load the longtable package. Then you can normally create tables and these tables will be breakable.
\documentclass{article}
\usepackage{longtable}
\usepackage{lipsum} % just for dummy text
\begin{document}
\lipsum[1]
\lipsum[1]
\lipsum[1]
\lipsum[1][1-8]
\begin{longtable}{| p{0.4\textwidth} | p{0.4\textwidth} |}
\hline
\textbf{Head1} & \textbf{Head2} \\ \hline
1 & 2 \\ \hline
3 & 4 \\ \hline
5 & 6 \\ \hline
7 & 8 \\ \hline
9 & 10 \\ \hline
11 & 12 \\ \hline
13 & 14 \\ \hline
15 & 16 \\ \hline
17 & 18 \\ \hline
\caption{This is a breakable table}
\end{longtable}
\end{document}Output:

Table span multiple pages with the heading
In the above example, you can notice that the heading in not appear on the next page. To get the heading on the next page also, you have to specify the head row two times and separate them with the \endfirsthead and \endhead commands. There are also available \endfoot and \endlastfoot commands to make repeatable footers.
The \endfirsthead, \endhead, \endfoot, and \endlastfoot commands are used to specify the content that should be repeated at the top and bottom of each page.
\documentclass{article}
\usepackage{longtable}
\usepackage{lipsum} % just for dummy text
\begin{document}
\lipsum[1]
\lipsum[1]
\lipsum[1]
\lipsum[1][1-8]
\begin{longtable}{| p{0.4\textwidth} | p{0.4\textwidth} |}
\hline
\textbf{Head1} & \textbf{Head2} \\
\hline
\endfirsthead
\hline
\textbf{Head1} & \textbf{Head2} \\
\hline
\endhead
% You can also use the below code for more things
% \hline
% \endfoot
% \hline
% \endlastfoot
1 & 2 \\ \hline
3 & 4 \\ \hline
5 & 6 \\ \hline
7 & 8 \\ \hline
9 & 10 \\ \hline
11 & 12 \\ \hline
13 & 14 \\ \hline
15 & 16 \\ \hline
17 & 18 \\ \hline
\caption{This is a breakable table}
\label{tab:breakable}
\end{longtable}
\end{document}Output:

Specify manually where the table should be broken
You can also break the table any whatever position you want with the \pagebreak command. You just place this command where you want to break the table.
You can also use this command multiple times to break the table on multiple pages.
In the below example, I placed the \pagebreak command after the 3rd row.
\documentclass{article}
\usepackage{longtable}
\usepackage{lipsum} % just for dummy text
\begin{document}
\lipsum[1]
\lipsum[1]
\lipsum[1]
\lipsum[1][1-8]
\begin{longtable}{| p{0.4\textwidth} | p{0.4\textwidth} |}
\hline
\textbf{Head1} & \textbf{Head2} \\
\hline
\endfirsthead
\hline
\textbf{Head1} & \textbf{Head2} \\
\hline
\endhead
1 & 2 \\ \hline
3 & 4 \\ \hline
5 & 6 \\ \hline
\pagebreak
7 & 8 \\ \hline
9 & 10 \\ \hline
11 & 12 \\ \hline
13 & 14 \\ \hline
15 & 16 \\ \hline
17 & 18 \\ \hline
\caption{This is a breakable table}
\label{tab:breakable}
\end{longtable}
\end{document}Output:

Leave a Reply