将 threeparttable 表格转换为 threeparttablex 和 longtable

将 threeparttable 表格转换为 threeparttablex 和 longtable

我正在尝试将现有的转换threeparttablethreeparttablex表格,longtable以便我可以将该表格拆分为多个页面,但我遇到了一些问题。具体来说,我收到有关 \noalign 放错位置的错误\toprule。您知道我哪里做错了吗?

原来的:

\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}

新的:

\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}

奖励:我想Continued on next page在除最后一页之外的每一页的底部添加一条消息,并Table X Continued在除第一页之外的每一页上添加一条消息。

答案1

你必须\label{mytbl}caption点赞后移动你的

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

Continued on next page您可以按照与长表相同的方式放置:

  \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

此外,tablenotes环境必须由环境替换TableNotes,并且应放在之前\begin{longtable}。就在\endlastfoot你应该插入\insertTableNotes之前

\insertTableNotes         %% this added
\endlastfoot

完整代码:

\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}

在此处输入图片描述

相关内容