3

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} 
6
  • Typo, begin and end parts are not spelled correctly. Also you might want threeparttablex for this (which is probably where you got the spelling for the end part)
    – daleif
    Nov 14, 2015 at 18:42
  • Besides: please post full minimal examples, not sniplets
    – daleif
    Nov 14, 2015 at 18:43
  • Yes, please post a full minimal example. If possible, post both the .lyx file (which is just plain text) and the .tex file. For more information see wiki.lyx.org/FAQ/MinimalExample
    – scottkosty
    Nov 14, 2015 at 19:05
  • 1
    Why are you using the threeparttable code if there are no table notes?
    – Mico
    Nov 14, 2015 at 19:12
  • 1
    You shouldn't be using the threeparttable machinery to begin with when using a longtable. Instead, look into using the threeparttablex machinery.
    – Mico
    Nov 14, 2015 at 19:25

1 Answer 1

7

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}
5
  • thank you very much, Mico. I'd like to ask if perhaps you know ho to adjust regular table (when using threepartable ) to the textwidth of the text keeping the size of the letters the same ? (i.e increase distance between columns automatically)
    – user90561
    Nov 14, 2015 at 22:48
  • @user90561 - The closest analogue, in the single-page table group, would be a tabular* environment: Begin with \setlength\tabcolsep{0pt} inside a table environment, and then specify \begin{tabular*}{\textwidth}{ l @{\extracolsep{\fill}} *{7}{c} } instead of \begin{longtable}{ l @{\extracolsep{\fill}} *{7}{c} }, and (later) \end{tabular*} instead of \end{longtable}.
    – Mico
    Nov 14, 2015 at 22:52
  • @user90561 - See also this answer to the question, How to force a table into page width?
    – Mico
    Nov 14, 2015 at 22:55
  • but within 'tabular' environment, i'll not be able to write appropriate table notes, i think. or i'm mistaken?
    – user90561
    Nov 14, 2015 at 22:55
  • @user90561 - You need to write \begin{table}, \begin{threeparttable}, the caption, the tabular* environment, the tablenotes environment, followed by \end{threeparttable} and \end{table}.
    – Mico
    Nov 14, 2015 at 22:58

You must log in to answer this question.

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