3

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}
4
  • 3
    Don't use a table environment around the longtable. table never breaks over pages. May 30, 2018 at 14:26
  • 3
    Do not enclose a longtable environment with a floating table environment that disallows pagebreaks. Also, longtable offers its own caption mechanism.
    – leandriis
    May 30, 2018 at 14:26
  • 1
    also longtable does not have an [h] option May 30, 2018 at 15:07
  • 1
    and never do \begin{flushleft} \noindent \caption{table title} \end{flushleft} in normal tables!! just use \caption{table title} the whole idea is that the caption formatting is specified elsewhere preferably in the document class. The \noindent is unlikely to affect the caption. May 30, 2018 at 15:10

1 Answer 1

6

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}
6
  • +1, but isn't \em in latex deprecated? :-)
    – Zarko
    May 30, 2018 at 18:48
  • @Zarko - Absolutely not. In fact, the macro \emph{...} is defined as {\em ...}. (Mostly, though, I wrote \em in the answer because it's shorter than \itshape...)
    – Mico
    May 30, 2018 at 19:11
  • also I noticed there's a \midrule before each section, one of my sections starts on a new page and it's creating an extra line under the header. Is the solution to just take out that midline? Table position might change due to edits so I might have to stick it back in later..
    – Ally D
    May 31, 2018 at 9:02
  • Thank you @Mico! This was super helpful. I have a couple additional questions (I am a noob I'm sorry) - what is the {@{}l} for in \multicolumn{3}{@{}l}{\textit{Section 2}} \` ? I know the l left justifies but confused about the @. Also in the \begin{longtable} line. Also how can I make this line \cmidrule(r){1-1} longer?
    – Ally D
    May 31, 2018 at 9:03
  • sorry comments out of order, took too long editing one and had to delete it ...
    – Ally D
    May 31, 2018 at 9:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .