重复子标题 Latex longtable

重复子标题 Latex longtable

我正在为一份统计报告制作人口统计数据列表。每个表格都有标题,表明所涉及的受试者类型(例如,治疗组与对照组)。然后表格有垂直排列的子标题,如年龄、性别、种族,缩进行显示了每个值的格式化级别和计数。

比赛是一个特别长的副标题,因此当分页符时,我们再次看到处理/控制标题的显示,但比赛列表继续,没有任何副标题标签。如何让 Latex 在下一页列出标题和副标题(副标题在整个表格中发生变化)?

这是现有的 tex 文件(已删除身份信息)

\documentclass{article}
\usepackage{longtable}

\begin{document}

\footnotesize

\begin{center}

\begin{longtable}{lrrrrrr}
 & \multicolumn{2}{c}{ \begin{tabular}{c} \textbf{ Mastectomy }      \\ (N =  XX ) \end{tabular}}
 & \multicolumn{2}{c}{ \begin{tabular}{c} \textbf{ Other therapies } \\ (N =  XX ) \end{tabular}}
 & \multicolumn{2}{c}{ \begin{tabular}{c} \textbf{ Total }           \\ (N =  XX ) \end{tabular}} \endhead \\ 
\textbf{Diagnosis}; n (\%) &  &  &  &  &  &  \\
\hspace{3mm} Under XX years & X & (X.X) & X & (X.X) & X & (X.X) \\
\hspace{3mm} XX-XX years & X & (X.X) & X & (X.X) & X & (X.X) \\
\hspace{3mm} XX-XX years & X & (X.X) & X & (X.X) & X & (X.X) \\
\hspace{3mm} XX-XX years & X & (X.X) & X & (X.X) & X & (X.X) \\
\hspace{3mm} XX-XX years & X & (XX.X) & X & (X.X) & X & (X.X) \\
\hspace{3mm} XX-XX years & X & (X.X) & X & (X.X) & X & (X.X) \\
\hspace{3mm} XX-XX years & X & (XX.X) & X & (X.X) & X & (X.X) \\
\hspace{3mm} XX-XX years & X & (X.X) & X & (X.X) & X & (X.X) \\
\hspace{3mm} XX-XX years & XX & (XX.X) & XX & (XX.X) & XX & (XX.X) \\
\hspace{3mm} XX+ years & X & (XX.X) & XX & (XX.X) & XX & (XX.X) \\
\hspace{3mm} unanswered & X & (X.X) & X & (X.X) & X & (X.X) \\
\textbf{MaritalStatus}; n (\%) &  &  &  &  &  &  \\
\hspace{3mm} single & X & (X.X) & X & (X.X) & X & (X.X) \\
\hspace{3mm} not married but have a significant other & X & (X.X) & X & (X.X) & X & (X.X) \\
\hspace{3mm} married & XX & (XX.X) & XX & (XX.X) & XX & (XX.X) \\
\hspace{3mm} separated & X & (X.X) & X & (X.X) & X & (X.X) \\
\hspace{3mm} divorced & X & (X.X) & X & (X.X) & X & (X.X) \\
\hspace{3mm} widowed & X & (XX.X) & X & (XX.X) & XX & (XX.X) \\
\hspace{3mm} unanswered & X & (X.X) & X & (X.X) & X & (X.X) \\
\textbf{Education}; n (\%) &  &  &  &  &  &  \\
\hspace{3mm} less than high school & X & (X.X) & X & (X.X) & X & (X.X) \\
\hspace{3mm} high school/GED & XX & (XX.X) & XX & (XX.X) & XX & (XX.X) \\
\hspace{3mm} some college & X & (XX.X) & XX & (XX.X) & XX & (XX.X) \\
\hspace{3mm} college degree: associates & X & (XX.X) & X & (X.X) & X & (X.X) \\
\hspace{3mm} college degree: bachelors & XX & (XX.X) & XX & (XX.X) & XX & (XX.X) \\
\hspace{3mm} masters degree & X & (XX.X) & XX & (XX.X) & XX & (XX.X) \\
\hspace{3mm} doctorate degree & X & (X.X) & X & (X.X) & X & (X.X) \\
\hspace{3mm} unanswered & X & (X.X) & X & (X.X) & X & (X.X) \\
\textbf{EmployStatus}; n (\%) &  &  &  &  &  &  \\
\hspace{3mm} employed, part time & X & (X.X) & XX & (XX.X) & XX & (XX.X) \\
\hspace{3mm} employed, full time & XX & (XX.X) & X & (XX.X) & XX & (XX.X) \\
\hspace{3mm} unemployed & X & (XX.X) & X & (X.X) & X & (X.X) \\
\hspace{3mm} retired & XX & (XX.X) & XX & (XX.X) & XX & (XX.X) \\
\hspace{3mm} unanswered & X & (X.X) & X & (X.X) & X & (X.X) \\
\textbf{Hispanic}; n (\%) &  &  &  &  &  &  \\
\hspace{3mm} yes & X & (X.X) & X & (X.X) & X & (X.X) \\
\hspace{3mm} no & XX & (XX.X) & XX & (XX.X) & XX & (XX.X) \\
\hspace{3mm} unanswered & X & (X.X) & X & (X.X) & X & (X.X) \\
\textbf{Race}; n (\%) &  &  &  &  &  &  \\
\hspace{3mm} white & XX & (XX.X) & XX & (XX.X) & XX & (XX.X) \\
\hspace{3mm} black or african american & X & (X.X) & X & (X.X) & X & (X.X) \\
\hspace{3mm} asian & X & (X.X) & X & (X.X) & X & (X.X) \\
\hspace{3mm} native hawaiian/other pacific islander & X & (X.X) & X & (X.X) & X & (X.X) \\
\hspace{3mm} american indian or alaska native & X & (XX.X) & X & (X.X) & X & (X.X) \\
\hspace{3mm} other & X & (X.X) & X & (X.X) & X & (X.X) \\
\hspace{3mm} unanswered & X & (X.X) & X & (X.X) & X & (X.X) \\
\textbf{Religion}; n (\%) &  &  &  &  &  &  \\
\hspace{3mm} protestant christian & XX & (XX.X) & XX & (XX.X) & XX & (XX.X) \\
\hspace{3mm} roman catholic & XX & (XX.X) & XX & (XX.X) & XX & (XX.X) \\
\hspace{3mm} evangelical christian & X & (XX.X) & X & (X.X) & X & (X.X) \\
\hspace{3mm} jewish & X & (X.X) & X & (X.X) & X & (X.X) \\
\hspace{3mm} muslim & X & (X.X) & X & (X.X) & X & (X.X) \\
\hspace{3mm} hindu & X & (X.X) & X & (X.X) & X & (X.X) \\
\hspace{3mm} buddist & X & (X.X) & X & (X.X) & X & (X.X) \\
\hspace{3mm} other & X & (XX.X) & X & (XX.X) & XX & (XX.X) \\
\hspace{3mm} unanswered & X & (X.X) & X & (X.X) & X & (X.X) \\
\textbf{Help}; n (\%) &  &  &  &  &  &  \\
\hspace{3mm} yes & X & (X.X) & X & (X.X) & X & (X.X) \\
\hspace{3mm} no & XX & (XXX.X) & XX & (XX.X) & XX & (XX.X) \\
\hspace{3mm} unanswered & X & (X.X) & X & (X.X) & X & (X.X) \\
\textbf{ruca}; mean (sd) & X.X & (X.X) & X.X & (X.X) & X.X & (X.X) \\
\hspace{3mm} \textit{missing}; n [\%] & X & [X.X] & X & [X.X] & X & [X.X] \\
\end{longtable}
\end{center}
\end{document}

答案1

这不太对

 Overfull \hbox (0.13614pt too wide) in alignment at lines 109--113

但它正在挖掘一些非常古老的代码:-)

在此处输入图片描述

\documentclass{article}
\usepackage{longtable}

\addtolength\oddsidemargin{-40pt}
\addtolength\textwidth{80pt}
\makeatletter
\def\LT@output{%
  \ifnum\outputpenalty <-\@Mi
    \ifnum\outputpenalty > -\LT@end@pen
      \LT@err{floats and marginpars not allowed in a longtable}\@ehc
    \else
      \setbox\z@\vbox{\unvbox\@cclv}%
      \ifdim \ht\LT@lastfoot>\ht\LT@foot
        \dimen@\pagegoal
        \advance\dimen@-\ht\LT@lastfoot
        \ifdim\dimen@<\ht\z@
          \setbox\@cclv\vbox{\unvbox\z@\copy\LT@foot\vss}%
          \@makecol
          \@outputpage
          \setbox\z@\vbox{\box\LT@head}%
        \fi
      \fi
      \global\@colroom\@colht
      \global\vsize\@colht
      \vbox
        {\unvbox\z@\box\ifvoid\LT@lastfoot\LT@foot\else\LT@lastfoot\fi}%
    \fi
  \else
    \setbox\@cclv\vbox{\unvbox\@cclv\copy\LT@foot\vss}%
    \@makecol
    \@outputpage
      \global\vsize\@colroom
    \copy\LT@head\nobreak
\LT@bchunk\rlap{\currentheading\ (continued)}\LT@echunk
\unvbox\z@
  \fi}
\makeatother

\begin{document}


\footnotesize



\begin{longtable}{lrrrrrr}
 & \multicolumn{2}{c}{ \begin{tabular}{c} \textbf{ Mastectomy }      \\ (N =  XX ) \end{tabular}}
 & \multicolumn{2}{c}{ \begin{tabular}{c} \textbf{ Other therapies } \\ (N =  XX ) \end{tabular}}
 & \multicolumn{2}{c}{ \begin{tabular}{c} \textbf{ Total }           \\ (N =  XX ) \end{tabular}} \endhead \\ 
\textbf{Diagnosis}; n (\%) \gdef\currentheading{\textbf{Diagnosis}} &  &  &  &  &  &  \\
\hspace{3mm} Under XX years & X & (X.X) & X & (X.X) & X & (X.X) \\
\hspace{3mm} XX-XX years & X & (X.X) & X & (X.X) & X & (X.X) \\
\hspace{3mm} XX-XX years & X & (X.X) & X & (X.X) & X & (X.X) \\
\hspace{3mm} XX-XX years & X & (X.X) & X & (X.X) & X & (X.X) \\
\hspace{3mm} XX-XX years & X & (XX.X) & X & (X.X) & X & (X.X) \\
\hspace{3mm} XX-XX years & X & (X.X) & X & (X.X) & X & (X.X) \\
\hspace{3mm} XX-XX years & X & (XX.X) & X & (X.X) & X & (X.X) \\
\hspace{3mm} XX-XX years & X & (X.X) & X & (X.X) & X & (X.X) \\
\hspace{3mm} XX-XX years & XX & (XX.X) & XX & (XX.X) & XX & (XX.X) \\
\hspace{3mm} XX+ years & X & (XX.X) & XX & (XX.X) & XX & (XX.X) \\
\hspace{3mm} unanswered & X & (X.X) & X & (X.X) & X & (X.X) \\
\textbf{MaritalStatus}; n (\%) &  &  &  &  &  &  \\
\hspace{3mm} single & X & (X.X) & X & (X.X) & X & (X.X) \\
\hspace{3mm} not married but have a significant other & X & (X.X) & X & (X.X) & X & (X.X) \\
\hspace{3mm} married & XX & (XX.X) & XX & (XX.X) & XX & (XX.X) \\
\hspace{3mm} separated & X & (X.X) & X & (X.X) & X & (X.X) \\
\hspace{3mm} divorced & X & (X.X) & X & (X.X) & X & (X.X) \\
\hspace{3mm} widowed & X & (XX.X) & X & (XX.X) & XX & (XX.X) \\
\hspace{3mm} unanswered & X & (X.X) & X & (X.X) & X & (X.X) \\
\textbf{Education}; n (\%) &  &  &  &  &  &  \\
\hspace{3mm} less than high school & X & (X.X) & X & (X.X) & X & (X.X) \\
\hspace{3mm} high school/GED & XX & (XX.X) & XX & (XX.X) & XX & (XX.X) \\
\hspace{3mm} some college & X & (XX.X) & XX & (XX.X) & XX & (XX.X) \\
\hspace{3mm} college degree: associates & X & (XX.X) & X & (X.X) & X & (X.X) \\
\hspace{3mm} college degree: bachelors & XX & (XX.X) & XX & (XX.X) & XX & (XX.X) \\
\hspace{3mm} masters degree & X & (XX.X) & XX & (XX.X) & XX & (XX.X) \\
\hspace{3mm} doctorate degree & X & (X.X) & X & (X.X) & X & (X.X) \\
\hspace{3mm} unanswered & X & (X.X) & X & (X.X) & X & (X.X) \\
\textbf{EmployStatus}; n (\%) &  &  &  &  &  &  \\
\hspace{3mm} employed, part time & X & (X.X) & XX & (XX.X) & XX & (XX.X) \\
\hspace{3mm} employed, full time & XX & (XX.X) & X & (XX.X) & XX & (XX.X) \\
\hspace{3mm} unemployed & X & (XX.X) & X & (X.X) & X & (X.X) \\
\hspace{3mm} retired & XX & (XX.X) & XX & (XX.X) & XX & (XX.X) \\
\hspace{3mm} unanswered & X & (X.X) & X & (X.X) & X & (X.X) \\
\textbf{Hispanic}; n (\%) &  &  &  &  &  &  \\
\hspace{3mm} yes & X & (X.X) & X & (X.X) & X & (X.X) \\
\hspace{3mm} no & XX & (XX.X) & XX & (XX.X) & XX & (XX.X) \\
\hspace{3mm} unanswered & X & (X.X) & X & (X.X) & X & (X.X) \\
\textbf{Race}; n (\%) \gdef\currentheading{\textbf{Race}} &  &  &  &  &  &  \\
\hspace{3mm} white & XX & (XX.X) & XX & (XX.X) & XX & (XX.X) \\
\hspace{3mm} black or african american & X & (X.X) & X & (X.X) & X & (X.X) \\
\hspace{3mm} asian & X & (X.X) & X & (X.X) & X & (X.X) \\
\hspace{3mm} native hawaiian/other pacific islander & X & (X.X) & X & (X.X) & X & (X.X) \\
\hspace{3mm} american indian or alaska native & X & (XX.X) & X & (X.X) & X & (X.X) \\
\hspace{3mm} other & X & (X.X) & X & (X.X) & X & (X.X) \\
\hspace{3mm} unanswered & X & (X.X) & X & (X.X) & X & (X.X) \\
\textbf{Religion}; n (\%) &  &  &  &  &  &  \\
\hspace{3mm} protestant christian & XX & (XX.X) & XX & (XX.X) & XX & (XX.X) \\
\hspace{3mm} roman catholic & XX & (XX.X) & XX & (XX.X) & XX & (XX.X) \\
\hspace{3mm} evangelical christian & X & (XX.X) & X & (X.X) & X & (X.X) \\
\hspace{3mm} jewish & X & (X.X) & X & (X.X) & X & (X.X) \\
\hspace{3mm} muslim & X & (X.X) & X & (X.X) & X & (X.X) \\
\hspace{3mm} hindu & X & (X.X) & X & (X.X) & X & (X.X) \\
\hspace{3mm} buddist & X & (X.X) & X & (X.X) & X & (X.X) \\
\hspace{3mm} other & X & (XX.X) & X & (XX.X) & XX & (XX.X) \\
\hspace{3mm} unanswered & X & (X.X) & X & (X.X) & X & (X.X) \\
\textbf{Help}; n (\%) &  &  &  &  &  &  \\
\hspace{3mm} yes & X & (X.X) & X & (X.X) & X & (X.X) \\
\hspace{3mm} no & XX & (XXX.X) & XX & (XX.X) & XX & (XX.X) \\
\hspace{3mm} unanswered & X & (X.X) & X & (X.X) & X & (X.X) \\
\textbf{ruca}; mean (sd) & X.X & (X.X) & X.X & (X.X) & X.X & (X.X) \\
\hspace{3mm} \textit{missing}; n [\%] & X & [X.X] & X & [X.X] & X & [X.X] \\
\end{longtable}

\end{document}

相关内容