[Tex/LaTex] page not breaking with longtable

longtable

I realize this question has been asked in many forms but from the responses I've read so far and the longtable documentation, I can't figure out where I'm going wrong. I want the table to break naturally where the rest of the text breaks. Currently the table is going down further than the bottom margin I have set and overlapping with the page number.

I tried using \pagebreak and \newpage to no avail. Also tried sticking \hline where I would normally put \ at the end of a line, and still no luck.

Any help is appreciated, thanks!

MWE:

\begin{table}

\begin{flushleft}
\noindent \caption{table title}
\end{flushleft} 

\footnotesize
\begin{longtable}[h]{p{0.15\linewidth}p{0.6\linewidth}p{0.15\linewidth}}
\toprule
\textbf{Factor} & \textbf{Roles} & \textbf{References}  \endhead
\midrule 
\multicolumn{3}{l}{\textit{section1}} \\
\midrule
ATX & 
Roles \newline
Role2 &
Refs here \\
\midrule
CXCLs & 
Roles \newline
Role2 &
Refs here \\
\midrule
Endothelin-2 & 
Roles \newline
Role2 &
Refs here \\
\midrule
IGF-1 & 
Roles \newline
Role2 &
Refs here \\
\midrule
Laminin-2 & 
Roles \newline
Role2 &
Refs here \\
\midrule
PDGF-A & 
Roles \newline
Role2 &
Refs here \\
\midrule
Retinoic Acid & 
Roles \newline
Role2 &
Refs here \\
\midrule
Sema3F & 
Roles \newline
Role2 &
Refs here \\
\midrule 
\multicolumn{3}{l}{\textit{section2}} \\
\midrule
BMPs & 
Roles \newline
Role2 &
Refs here \\
\midrule
Hyaluronan & 
Roles \newline
Role2 &
Refs here \\
\midrule
LINGO-1 & 
Roles \newline
Role2 &
Refs here \\
\midrule
Notch-1 & 
Roles \newline
Role2 &
Refs here \\
\midrule
Sema3A & 
Roles \newline
Role2 &
Refs here \\
\multicolumn{3}{l}{\textit{section3}} \\
\midrule
Fibronectin & 
Roles \newline
Role2 &
Refs here \\
\midrule
FGF &
Roles \newline
Role2 &
Refs here \\
\midrule
GPR17 & 
Roles \newline
Role2 &
Refs here \\
\midrule
Netrin-1 & 
Roles \newline
Role2 &
Refs here \\
\midrule
PSA-NCAM & 
Roles \newline
Role2 &
Refs here \\
\midrule
S1P & 
Roles \newline
Role2 &
Refs here \\
\midrule
Wnt/$\beta$-catenin & 
Roles \newline
Role2 &
Refs here \\
\bottomrule
\end{longtable}
\end{table}

Best Answer

In addition to the pieces of advice already given -- don't encase a longtable environment in a table environment; use the \caption command properly; don't provide a useless [h] location specifier (since longtables don't float) -- you should also make better use of the longtable machinery -- specifically, the \endfirsthead, \endhead, \endfoot, and \endlastfoot -- to provide some needed structure to the table's material. Also, don't overuse horizontal lines where (vertical) whitespace is just as effective.

enter image description here

...

enter image description here

\documentclass{article}
\usepackage{longtable,booktabs}
% Set up two length variables to store widths of 1st and 3rd columns
\newlength\mylena
\settowidth{\mylena}{Endothelin-2}
\newlength\mylenb
\settowidth{\mylenb}{\textbf{References}} 

\begin{document}

\begin{longtable}{@{} p{\mylena}p{0.6\linewidth}p{\mylenb}@{}}

%% Define headers and footers
\caption{Table title}\\
\toprule
\textbf{Factor} & \textbf{Roles} & \textbf{References} \\ \midrule 
\endfirsthead

\multicolumn{3}{@{}l}{Table \thetable, continued}\\
\addlinespace
\toprule
\textbf{Factor} & \textbf{Roles} & \textbf{References} \\ \midrule 
\endhead

\midrule
\multicolumn{3}{r@{}}{\em\small (continued on next page)}\\
\endfoot

\bottomrule
\endlastfoot

%% Body of table
\multicolumn{3}{@{}l}{\textit{Section 1}} \\
\cmidrule(r){1-1}  % no need to extend this line across full width of table
ATX & 
Roles \newline
Role2 &
Refs here \\
\addlinespace
CXCLs & 
Roles \newline
Role2 &
Refs here \\
\addlinespace
Endothelin-2 & 
Roles \newline
Role2 &
Refs here \\
\addlinespace
IGF-1 & 
Roles \newline
Role2 &
Refs here \\
\addlinespace
Laminin-2 & 
Roles \newline
Role2 &
Refs here \\
\addlinespace
PDGF-A & 
Roles \newline
Role2 &
Refs here \\
\addlinespace
Retinoic Acid & 
Roles \newline
Role2 &
Refs here \\
\addlinespace
Sema3F & 
Roles \newline
Role2 &
Refs here \\
\midrule 
\multicolumn{3}{@{}l}{\textit{Section 2}} \\
\cmidrule(r){1-1}
BMPs & 
Roles \newline
Role2 &
Refs here \\
\addlinespace
Hyaluronan & 
Roles \newline
Role2 &
Refs here \\
\addlinespace
LINGO-1 & 
Roles \newline
Role2 &
Refs here \\
\addlinespace
Notch-1 & 
Roles \newline
Role2 &
Refs here \\
\addlinespace
Sema3A & 
Roles \newline
Role2 &
Refs here \\
\midrule
\multicolumn{3}{@{}l}{\textit{Section 3}} \\
\cmidrule(r){1-1}
Fibronectin & 
Roles \newline
Role2 &
Refs here \\
\addlinespace
FGF &
Roles \newline
Role2 &
Refs here \\
\addlinespace
GPR17 & 
Roles \newline
Role2 &
Refs here \\
\addlinespace
Netrin-1 & 
Roles \newline
Role2 &
Refs here \\
\addlinespace
PSA-NCAM & 
Roles \newline
Role2 &
Refs here \\
\addlinespace
S1P & 
Roles \newline
Role2 &
Refs here \\
\addlinespace
Wnt\slash \mbox{$\beta$-catenin} & 
Roles \newline
Role2 &
Refs here \\

\end{longtable}
\end{document}
Related Question