2

I am producing listings of demographics for a statistical report. We have headings on each table that indicate the types of subjects accounted for (say, treated versus control). Then the table has subheadings like Age, Sex, Race vertically with indented rows showing formatted levels and counts for each of these values.

Race is a particularly long subheading, so as the page breaks, we see again the display of the treated / control heading, but the race listing continues without any label for the subheading. How do I get Latex to list the heading and the subheading on the next page (where the subheading changes throughout the table)?

Here is the existing tex file (deidentified)

\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}
  • without a complete example document showing the problem (every question should have a complete test document) it is hard to say, but if you mean what I think you mean the answer might be that it is hard to do automatically in longtable, LT really assumes a fixed (but repeating) header and doesn't make it easy to change the header or add rows dynamically. – David Carlisle Jan 16 '15 at 21:12
  • @DavidCarlisle I included the tex file, but you have described the problem I am getting at. That's unfortunate. – AdamO Jan 16 '15 at 21:33
  • it's not actually runnable in latex as it is 9Ive used longtable before and could guess, but I can't guess your page size etc. also center doesn't do anything to lonngtable other than add some spurious vertical space – David Carlisle Jan 16 '15 at 21:36
  • \multicolumn{X} ? – David Carlisle Jan 16 '15 at 21:37
  • @DavidCarlisle sorry, deidentified I replaced [0-9] with X and accidentally missed some formatting. This should be entirely cut-and-paste ready – AdamO Jan 16 '15 at 21:44
1

This isn't quite right

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

but it's digging in some very old code:-)

enter image description here

\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}
  • Haha thank you for pointing that out. Coincidentally, a second round of building the pdf usually corrects the indenting. I didn't know longtable does not allow for indenting, it's such a critical part of building tables as it helps to display subheadings (the crux of the issue at hand). – AdamO Jan 17 '15 at 16: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.