[Tex/LaTex] How to use longtable in latex

longtabletables

I have a really long table and it does not fit the page. So, I want it to span on several pages. When I google about my issue, I came accross longtable. However, it seems like longtable do not support tabular format. Is there a way to resolve this issue?

\documentclass[jou,apacite]{apa6}
\usepackage{multirow}
\usepackage{array}
\newcolumntype{P}[1]{>{\centering\arraybackslash}p{#1}}
\usepackage{longtable}
\begin{document}

\begin{longtable*}[!t]
\renewcommand{\arraystretch}{1.3}
\caption{My data}
\centering
\begin{tabular}{|p{2.8cm}|p{0.6cm}|p{1.6cm}|p{2.2cm}|P{0.8cm}|p{2.6cm}|p{2.5cm}|}
\hline
\textbf{Name} & \textbf{Year} & \textbf{ID} & \textbf{Address} & \textbf{Salary} & \textbf{Skills} & \textbf{Qualifications} \\
\hline
Some text & some text & some text & 5 & some text & Som text
\hline
\end{tabular}
\label{table3}
\end{longtable*}
\end{document}

Please let me know if any further details are needed. 🙂

EDIT

I did not just post the question without looking at any materials or other questions. I also tried the solution in How to convert table to longtable being able to break across pages?. However, that did not work either. That is why I posted the question.

Best Answer

You have several issues in your given code, for example command \label has to follow \caption ...

You should not use verticals lines and instead of \hline have better a look to package booktabs (type texdoc booktabs on your terminal/console) ...

How you get the title back for the second page I left over for you. Please read the manual of longtable (type texdoc longtable on your terminal/console) ...

With the following corrected code

\documentclass[jou,apacite]{apa6}
\usepackage{multirow}
\usepackage{array}
\newcolumntype{P}[1]{>{\centering\arraybackslash}p{#1}}
\usepackage{longtable}

\usepackage{showframe} % to visualize writing area and margins ...
\usepackage{blindtext} % to generate dummy text


\begin{document}

\Blindtext
\renewcommand{\arraystretch}{1.3}

\begin{longtable}{|p{2.8cm}|p{0.6cm}|p{1.6cm}|p{2.2cm}|P{0.8cm}|p{2.6cm}|p{2.5cm}|}
\caption{My data}
\label{tab:table3}\\
\hline
\textbf{Name} & \textbf{Year} & \textbf{ID} & \textbf{Address} & \textbf{Salary} & \textbf{Skills} & \textbf{Qualifications} \\
\hline
Some text & some text & some text & 5 & some text & Som text &\\
\hline
Some text & some text & some text & 5 & some text & Som text &\\
\hline
Some text & some text & some text & 5 & some text & Som text &\\
\hline
Some text & some text & some text & 5 & some text & Som text &\\
\hline
Some text & some text & some text & 5 & some text & Som text &\\
\hline
Some text & some text & some text & 5 & some text & Som text &\\
\hline
Some text & some text & some text & 5 & some text & Som text &\\
\hline
Some text & some text & some text & 5 & some text & Som text &\\
\hline
Some text & some text & some text & 5 & some text & Som text &\\
\hline
\end{longtable}
\blindtext
\end{document}

you get the result:

enter image description here