0

although the question seems to be trivial and to be answered several times, I have not found a solution yet :-( I'm using a longtable to describe a set of computer benchmarks. Each benchmark entry consists of rows, a "headline" (name, references), and a "description". Now I do not want longtable to split the headline row and the description row, but print them on the same page. This can be done using \\*. Now the problem is that I want to have a \hline between the headline and the description, but both potential options do not work:

  • \\\hline * : Latex compile error
  • \\*\hline : The headline and the description are split

Is there a way to achieve this? Thank you!

  • Is there anything that resembls a MWE? – user11232 Jul 31 '14 at 9:59
  • easiest way is to ignore it unless it happens and if it does happen, force a page break after the previous row – David Carlisle Jul 31 '14 at 10:37
  • you could make a feature request for longtable v5 but it's been 18 years since longtable v4 came out.... – David Carlisle Jul 31 '14 at 10:40
1

You can put your headline and description inside a separate tabular inside the same row of longtable. You can even make a macro for it like:

\newcommand{\benchmark}[2]{%
\begin{tabular}{@{}p{\linewidth}@{}}
 #1 \\ \midrule
 #2
 \end{tabular}%
 }

The full code:

\documentclass{article}
\usepackage{longtable,booktabs}
\usepackage[textheight=3cm]{geometry}   %% 3cm only for demo
\newcommand{\benchmark}[2]{%
\begin{tabular}{@{}p{\linewidth}@{}}
 #1 \\ \midrule
 #2
 \end{tabular}%
 }
\begin{document}
  \begin{longtable}{@{}l@{}}\toprule[1pt]
  \endfirsthead
  \toprule[1pt]
  \endhead
    \benchmark{Headline}{Some Description}\\\toprule[1pt]
    \benchmark{Headline}{Some Description}\\\toprule[1pt]
    \benchmark{Headline}{Some Description}\\\toprule[1pt]
    \benchmark{Headline}{Some Description}\\\toprule[1pt]
    \benchmark{Headline}{Some Description}\\\toprule[1pt]
  \end{longtable}
\end{document}

enter image description here

  • it's harder to do this in the general case that the table has multiple columns and you don't know their widths in advance – David Carlisle Jul 31 '14 at 12:13
  • @DavidCarlisle True. But for simple cases like this, we can do some circus ;) – user11232 Jul 31 '14 at 23:59
  • Although I hoped for a "nice" solution, this works, as well :-) Thank you! – strauberry Aug 22 '14 at 12:31

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.