5

This is similar to How to disable pagebreak on \hline in longtable? but for supertabular or xtab: With \tabularnewline\hline I get pagebreaks (or in my case columnbreaks) before the hline, i.e. the hline appears at the top of the next column. I'm using this code to make supertabular work inside multicols.

How can I change this so that the hline is kept together with the row?

1 Answers1

7

This takes the example in the question you cited and redefines supertab's \\ to look ahead for \hline and suck it back before the page breaking code. this version doesn't take care if \hline\hline but could be extended.

\documentclass{article}
\usepackage[margin=1in]{geometry}
\usepackage{xcolor,supertabular,multicol}
\newcount\n
\n=0
\def\tablebody{}
\makeatletter
\let\zz\hline
\let\hline\relax
\loop\ifnum\n<300
        \advance\n by1
        \protected@edef\tablebody{\tablebody
                \textbf{\number\n.}&
                \hfill T\hfill\hfill F\hfill\hskip0pt\endgraf
                \vskip.5\baselineskip
                \color@begingroup
                \color{black!20}
                \hrule height3ex
                \color@endgroup
                \tabularnewline\hline
        }
\repeat
\makeatother
\let\hline\zz

\pagestyle{empty}
\begin{document}
\begin{multicols*}{2}
\let\mcnewpage=\newpage
\makeatletter
\renewcommand\newpage{%
        \if@firstcolumn
                \hrule width\linewidth height0pt
                \columnbreak
        \else
                \mcnewpage
        \fi
}

\let\savedST@cr\ST@cr
\def\ST@cr{\noalign{\ifnum0=`}\fi\futurelet\st@temp\ST@crhline}
\def\ST@crhline{%
  \ifx\st@temp\hline
    \global\let\next@a\hline
    \global\let\next@b\@gobble
  \else
    \global\let\next@a\@empty
    \global\let\next@b\@empty
  \fi
  \ifnum0=`{\fi}%
\next@a
\savedST@cr
\next@b}

\makeatother
\tablehead{Item \#&\\}
\begin{supertabular}{lp{1.5in}}
\tablebody
\end{supertabular}
\end{multicols*}
\end{document}
David Carlisle
  • 757,742