[Tex/LaTex] Longtable with threeparttable

longtablelyxthreeparttablethreeparttablex

Can anyone help me to figure out why this code does not work in Lyx? Despite using longtable, the table gets truncated at the end of page after overflowing the bottom margin.

\begin{threeparttable}  
 \begin{longtable}{@{\hskip\tabcolsep\extracolsep\fill}l*{7}{c}}
        \toprule
    Country & N obs  & Total years & No degree & High school & Some college,+ & smth & smth \\
    & & of education & & & & prestige score & income score \\ \hline  \multirow{2}{0mm}{Albania} & \multirow{2}{0mm}{16} & 12.1 & 9 & 31 & 59 & 48.4 & 32.1 \\
    \medskip  &  & (2.8) & (30) & (47) & (50) & (11.9) & (10.1) \\
    \medskip \multirow{2}{0mm}{Norway} & \multirow{2}{0mm}{229} & 12.2 & 8 & 28 & 65 & 47.0 & 31.0 \\
    \bottomrule
    \end{longtable}
\end{threeparttable} 

Best Answer

You shouldn't be using the threeparttable package and its eponymous environment to encase a longtable environment. Instead, use the threeparttablex package. (Note that its syntax is not the same as that of the threeparttable package.)

enter image description here

\documentclass{article}
\usepackage[margin=1in,a4paper]{geometry} % page parameters
\usepackage{longtable,booktabs,threeparttablex}
\begin{document}

\begin{ThreePartTable}
\renewcommand\TPTminimum{\textwidth}
%% Arrange for "longtable" to take up full width of text block
\setlength\LTleft{0pt}
\setlength\LTright{0pt}
\setlength\tabcolsep{0pt}

\begin{TableNotes}
  \item[a] A note
  \item[b] Another note
\end{TableNotes}

\begin{longtable}{ l @{\extracolsep{\fill}} *{7}{c} }
\toprule
Country & N obs  & Total years & No degree & High school & Some college,+ & smth\tnote{a} & smth\tnote{b} \\
& & of education & & & & prestige score & income score \\ 
\midrule
\endhead

\midrule[\heavyrulewidth]
\multicolumn{8}{r}{\textit{continued}}\\
\endfoot  

\midrule[\heavyrulewidth]
\insertTableNotes  % tell LaTeX where to insert the table-related notes
\endlastfoot

Albania & 16 & 12.1 & 9 & 31 & 59 & 48.4 & 32.1 \\
&  & (2.8) & (30) & (47) & (50) & (11.9) & (10.1) \\
\addlinespace
Norway & 229 & 12.2 & 8 & 28 & 65 & 47.0 & 31.0 \\

\end{longtable}   
\end{ThreePartTable}

\end{document}