Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
1  
Would you be able to provide a minimal working example (MWE)? Call me lazy, but I find it much easier to work with that piecing together code from different sources. –  Werner Dec 11 '11 at 8:15

1 Answer 1

up vote 6 down vote accepted

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}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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