1

I am trying to convert an existing threeparttable to a threeparttablex table with longtable so I can break the table over multiple pages, but I'm having some trouble. Specifically, I'm getting an error about a misplaced \noalign related to \toprule. Any ideas where I am going wrong?

Original:

\documentclass{article}

\usepackage{threeparttable}
\usepackage{booktabs}
\usepackage{dcolumn}
\usepackage{longtable}
\usepackage{threeparttablex}

\begin{document}

\begin{table}[H]
\centerline{\begin{threeparttable}
  \caption{My caption}
  \label{mytbl}
  \centering
  \begin{tabular}{lrrrrr}
  \toprule
      & \multicolumn{2}{c}{Grp 1} & \multicolumn{2}{c}{Grp 2} &  \\
      & \multicolumn{2}{c}{(\textit{n}=500)} & \multicolumn{2}{c}{(\textit{n}=500)} &  \\
      \cmidrule(lr){2-3} \cmidrule(lr){4-5} 
      Variable & \multicolumn{1}{r}{Mean} & \multicolumn{1}{r}{SD} & \multicolumn{1}{r}{Mean} & \multicolumn{1}{r}{SD} & p-value \\
      \midrule
  Variable & 11.11 & 1.11 & 11.11 & 1.11 & 0.111 \\
  \bottomrule
  \end{tabular}
  \begin{tablenotes}
  \small
  \item My notes
  \end{tablenotes}
  \end{threeparttable}}
\end{table}

\end{document}

New:

\documentclass{article}

\usepackage{threeparttable}
\usepackage{booktabs}
\usepackage{dcolumn}
\usepackage{longtable}
\usepackage{threeparttablex}

\begin{document}

\begin{ThreePartTable}
\begin{longtable}{lrrrrr}
  \caption{My caption}\\
  \label{mytbl}
  \toprule
  & \multicolumn{2}{c}{Grp 1} & \multicolumn{2}{c}{Grp 2} &  \\
  & \multicolumn{2}{c}{(\textit{n}=500)} & \multicolumn{2}{c}{(\textit{n}=500)} &  \\
  \cmidrule(lr){2-3} \cmidrule(lr){4-5} 
  Variable & \multicolumn{1}{r}{Mean} & \multicolumn{1}{r}{SD} & \multicolumn{1}{r}{Mean} & \multicolumn{1}{r}{SD} & p-value \\
  \midrule
  Variable & 11.11 & 1.11 & 11.11 & 1.11 & 0.111 \\
  Variable & 11.11 & 1.11 & 11.11 & 1.11 & 0.111 \\
  Variable & 11.11 & 1.11 & 11.11 & 1.11 & 0.111 \\
  Variable & 11.11 & 1.11 & 11.11 & 1.11 & 0.111 \\
  Variable & 11.11 & 1.11 & 11.11 & 1.11 & 0.111 \\
  Variable & 11.11 & 1.11 & 11.11 & 1.11 & 0.111 \\
  Variable & 11.11 & 1.11 & 11.11 & 1.11 & 0.111 \\
  Variable & 11.11 & 1.11 & 11.11 & 1.11 & 0.111 \\
  Variable & 11.11 & 1.11 & 11.11 & 1.11 & 0.111 \\
  Variable & 11.11 & 1.11 & 11.11 & 1.11 & 0.111 \\
  Variable & 11.11 & 1.11 & 11.11 & 1.11 & 0.111 \\
  Variable & 11.11 & 1.11 & 11.11 & 1.11 & 0.111 \\
  Variable & 11.11 & 1.11 & 11.11 & 1.11 & 0.111 \\
  Variable & 11.11 & 1.11 & 11.11 & 1.11 & 0.111 \\
  Variable & 11.11 & 1.11 & 11.11 & 1.11 & 0.111 \\
  Variable & 11.11 & 1.11 & 11.11 & 1.11 & 0.111 \\
  Variable & 11.11 & 1.11 & 11.11 & 1.11 & 0.111 \\
  Variable & 11.11 & 1.11 & 11.11 & 1.11 & 0.111 \\
  Variable & 11.11 & 1.11 & 11.11 & 1.11 & 0.111 \\
  Variable & 11.11 & 1.11 & 11.11 & 1.11 & 0.111 \\
  Variable & 11.11 & 1.11 & 11.11 & 1.11 & 0.111 \\
  Variable & 11.11 & 1.11 & 11.11 & 1.11 & 0.111 \\
  Variable & 11.11 & 1.11 & 11.11 & 1.11 & 0.111 \\
  Variable & 11.11 & 1.11 & 11.11 & 1.11 & 0.111 \\
  Variable & 11.11 & 1.11 & 11.11 & 1.11 & 0.111 \\
  Variable & 11.11 & 1.11 & 11.11 & 1.11 & 0.111 \\
  Variable & 11.11 & 1.11 & 11.11 & 1.11 & 0.111 \\
  Variable & 11.11 & 1.11 & 11.11 & 1.11 & 0.111 \\
  Variable & 11.11 & 1.11 & 11.11 & 1.11 & 0.111 \\
  Variable & 11.11 & 1.11 & 11.11 & 1.11 & 0.111 \\
  Variable & 11.11 & 1.11 & 11.11 & 1.11 & 0.111 \\
  Variable & 11.11 & 1.11 & 11.11 & 1.11 & 0.111 \\
  Variable & 11.11 & 1.11 & 11.11 & 1.11 & 0.111 \\
  Variable & 11.11 & 1.11 & 11.11 & 1.11 & 0.111 \\
  Variable & 11.11 & 1.11 & 11.11 & 1.11 & 0.111 \\
  Variable & 11.11 & 1.11 & 11.11 & 1.11 & 0.111 \\
  Variable & 11.11 & 1.11 & 11.11 & 1.11 & 0.111 \\
  Variable & 11.11 & 1.11 & 11.11 & 1.11 & 0.111 \\
  Variable & 11.11 & 1.11 & 11.11 & 1.11 & 0.111 \\
  Variable & 11.11 & 1.11 & 11.11 & 1.11 & 0.111 \\
  Variable & 11.11 & 1.11 & 11.11 & 1.11 & 0.111 \\
  Variable & 11.11 & 1.11 & 11.11 & 1.11 & 0.111 \\
  Variable & 11.11 & 1.11 & 11.11 & 1.11 & 0.111 \\
  Variable & 11.11 & 1.11 & 11.11 & 1.11 & 0.111 \\
  Variable & 11.11 & 1.11 & 11.11 & 1.11 & 0.111 \\
  Variable & 11.11 & 1.11 & 11.11 & 1.11 & 0.111 \\
  Variable & 11.11 & 1.11 & 11.11 & 1.11 & 0.111 \\
  \bottomrule
  \end{longtable}
  \begin{tablenotes}
  \small
  \item Note. My table notes here
  \end{tablenotes}
  \end{ThreePartTable}

  \end{document}

Bonus: I'd like to add a Continued on next page message at the bottom of every page except the last, and a Table X Continued message on every page but the first.

5

You have to move your \label{mytbl} just after the caption like

\caption{My caption}\label{mytbl}\\  
  \toprule

You can put the Continued on next page in the same way you do with a long table:

  \caption{My caption}\label{mytbl}\\  
  \toprule
  & \multicolumn{2}{c}{Grp 1} & \multicolumn{2}{c}{Grp 2} &  \\
  & \multicolumn{2}{c}{(\textit{n}=500)} & \multicolumn{2}{c}{(\textit{n}=500)} &  \\
  \cmidrule(lr){2-3} \cmidrule(lr){4-5}
  Variable & \multicolumn{1}{r}{Mean} & \multicolumn{1}{r}{SD} & \multicolumn{1}{r}{Mean} & \multicolumn{1}{r}{SD} & p-value \\
  \midrule
  \endfirsthead

\multicolumn{6}{c}{{\bfseries \tablename\ \thetable{} -- continued from previous
page}}\\
\toprule
  & \multicolumn{2}{c}{Grp 1} & \multicolumn{2}{c}{Grp 2} &  \\
  & \multicolumn{2}{c}{(\textit{n}=500)} & \multicolumn{2}{c}{(\textit{n}=500)} &  \\
  \cmidrule(lr){2-3} \cmidrule(lr){4-5}
  Variable & \multicolumn{1}{r}{Mean} & \multicolumn{1}{r}{SD} & \multicolumn{1}{r}{Mean} & \multicolumn{1}{r}{SD} & p-value \\
  \midrule    
\endhead

\midrule
\multicolumn{6}{r}{{Continued on next page}} \\
\midrule
\endfoot
\bottomrule
\endlastfoot

Further the tablenotes environment must be replaced by TableNotes environment and it should be put before the \begin{longtable}. Just before \endlastfoot you should insert \insertTableNotes like

\insertTableNotes         %% this added
\endlastfoot

Full code:

\documentclass{article}

\usepackage{threeparttable}
\usepackage{booktabs}
\usepackage{dcolumn}
\usepackage{longtable}
\usepackage{threeparttablex}

\begin{document}

\begin{ThreePartTable}
  \begin{TableNotes}  %%% This should come before longtable and it is not tablenotes but TableNotes
  \small
  \item Note. My table notes here
  \end{TableNotes}
\begin{longtable}{lrrrrr}
  \caption{My caption}\label{mytbl}\\
  \toprule
  & \multicolumn{2}{c}{Grp 1} & \multicolumn{2}{c}{Grp 2} &  \\
  & \multicolumn{2}{c}{(\textit{n}=500)} & \multicolumn{2}{c}{(\textit{n}=500)} &  \\
  \cmidrule(lr){2-3} \cmidrule(lr){4-5}
  Variable & \multicolumn{1}{r}{Mean} & \multicolumn{1}{r}{SD} & \multicolumn{1}{r}{Mean} & \multicolumn{1}{r}{SD} & p-value \\
  \midrule
  \endfirsthead

\multicolumn{6}{c}{{\bfseries \tablename\ \thetable{} -- continued from previous
page}}\\
\toprule
  & \multicolumn{2}{c}{Grp 1} & \multicolumn{2}{c}{Grp 2} &  \\
  & \multicolumn{2}{c}{(\textit{n}=500)} & \multicolumn{2}{c}{(\textit{n}=500)} &  \\
  \cmidrule(lr){2-3} \cmidrule(lr){4-5}
  Variable & \multicolumn{1}{r}{Mean} & \multicolumn{1}{r}{SD} & \multicolumn{1}{r}{Mean} & \multicolumn{1}{r}{SD} & p-value \\
  \midrule    
\endhead

\midrule
\multicolumn{6}{r}{{Continued on next page}} \\
\midrule
\endfoot
\bottomrule
\insertTableNotes         %% this added
\endlastfoot

  Variable & 11.11 & 1.11 & 11.11 & 1.11 & 0.111 \\
  Variable & 11.11 & 1.11 & 11.11 & 1.11 & 0.111 \\
  Variable & 11.11 & 1.11 & 11.11 & 1.11 & 0.111 \\
  Variable & 11.11 & 1.11 & 11.11 & 1.11 & 0.111 \\
  Variable & 11.11 & 1.11 & 11.11 & 1.11 & 0.111 \\
  Variable & 11.11 & 1.11 & 11.11 & 1.11 & 0.111 \\
  Variable & 11.11 & 1.11 & 11.11 & 1.11 & 0.111 \\
  Variable & 11.11 & 1.11 & 11.11 & 1.11 & 0.111 \\
  Variable & 11.11 & 1.11 & 11.11 & 1.11 & 0.111 \\
  Variable & 11.11 & 1.11 & 11.11 & 1.11 & 0.111 \\
  Variable & 11.11 & 1.11 & 11.11 & 1.11 & 0.111 \\
  Variable & 11.11 & 1.11 & 11.11 & 1.11 & 0.111 \\
  Variable & 11.11 & 1.11 & 11.11 & 1.11 & 0.111 \\
  Variable & 11.11 & 1.11 & 11.11 & 1.11 & 0.111 \\
  Variable & 11.11 & 1.11 & 11.11 & 1.11 & 0.111 \\
  Variable & 11.11 & 1.11 & 11.11 & 1.11 & 0.111 \\
  Variable & 11.11 & 1.11 & 11.11 & 1.11 & 0.111 \\
  Variable & 11.11 & 1.11 & 11.11 & 1.11 & 0.111 \\
  Variable & 11.11 & 1.11 & 11.11 & 1.11 & 0.111 \\
  Variable & 11.11 & 1.11 & 11.11 & 1.11 & 0.111 \\
  Variable & 11.11 & 1.11 & 11.11 & 1.11 & 0.111 \\
  Variable & 11.11 & 1.11 & 11.11 & 1.11 & 0.111 \\
  Variable & 11.11 & 1.11 & 11.11 & 1.11 & 0.111 \\
  Variable & 11.11 & 1.11 & 11.11 & 1.11 & 0.111 \\
  Variable & 11.11 & 1.11 & 11.11 & 1.11 & 0.111 \\
  Variable & 11.11 & 1.11 & 11.11 & 1.11 & 0.111 \\
  Variable & 11.11 & 1.11 & 11.11 & 1.11 & 0.111 \\
  Variable & 11.11 & 1.11 & 11.11 & 1.11 & 0.111 \\
  Variable & 11.11 & 1.11 & 11.11 & 1.11 & 0.111 \\
  Variable & 11.11 & 1.11 & 11.11 & 1.11 & 0.111 \\
  Variable & 11.11 & 1.11 & 11.11 & 1.11 & 0.111 \\
  Variable & 11.11 & 1.11 & 11.11 & 1.11 & 0.111 \\
  Variable & 11.11 & 1.11 & 11.11 & 1.11 & 0.111 \\
  Variable & 11.11 & 1.11 & 11.11 & 1.11 & 0.111 \\
  Variable & 11.11 & 1.11 & 11.11 & 1.11 & 0.111 \\
  Variable & 11.11 & 1.11 & 11.11 & 1.11 & 0.111 \\
  Variable & 11.11 & 1.11 & 11.11 & 1.11 & 0.111 \\
  Variable & 11.11 & 1.11 & 11.11 & 1.11 & 0.111 \\
  Variable & 11.11 & 1.11 & 11.11 & 1.11 & 0.111 \\
  Variable & 11.11 & 1.11 & 11.11 & 1.11 & 0.111 \\
  Variable & 11.11 & 1.11 & 11.11 & 1.11 & 0.111 \\
  Variable & 11.11 & 1.11 & 11.11 & 1.11 & 0.111 \\
  Variable & 11.11 & 1.11 & 11.11 & 1.11 & 0.111 \\
  Variable & 11.11 & 1.11 & 11.11 & 1.11 & 0.111 \\
  Variable & 11.11 & 1.11 & 11.11 & 1.11 & 0.111 \\
  Variable & 11.11 & 1.11 & 11.11 & 1.11 & 0.111 \\
  Variable & 11.11 & 1.11 & 11.11 & 1.11 & 0.111 \\
  %\bottomrule
  \end{longtable}
  \end{ThreePartTable}

  \end{document}

enter image description here

  • this is excellent! Very helpful notations. Thanks for taking the time to explain it. – Eric Green Aug 14 '14 at 11:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.