Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

longtable : provide a non breakable \hline #1389

Open
chrisaga opened this issue Jun 21, 2024 · 9 comments
Open

longtable : provide a non breakable \hline #1389

chrisaga opened this issue Jun 21, 2024 · 9 comments

Comments

@chrisaga
Copy link

Brief outline of the enhancement

Provide a version of \hline which don't allow page breaks since ending a table row with \\* is useless when followed by \hline.
For consistency this new version of \hline could be named \hline*.

Minimal example showing the current behaviour

\RequirePackage{latexbug}       % <--should be always the first line (see CONTRIBUTING)!
\documentclass{article}
\usepackage{longtable}

\begin{document}
  \begin{longtable}{@{*}r||p{1in}@{*}}
    Some & text \\
    Page break not & allowed after this line \\*
    Some & text \\
    Suppose we don't want a break & but need a line \\* % this won't work
    \hline                                              % because \hline allows a page break
    Some & text \\
  \end{longtable}
  
\end{document}

Minimal example showing the desired new behaviour

\RequirePackage{latexbug}       % <--should be always the first line (see CONTRIBUTING)!
\documentclass{article}
\usepackage{longtable}

\begin{document}
  \begin{longtable}{@{*}r||p{1in}@{*}}
    Some & text \\
    Page break not & allowed after this line \\*
    Some & text \\
    Suppose we don't want a break & but need a line \\
    \hline*                     % the new \hline* does this
    Some & text \\
  \end{longtable}
  
\end{document}

Working implementation

From tex.stackexchange.com here: https://tex.stackexchange.com/a/107893/211737

\def\nobreakhline{%
\noalign{\ifnum0=`}\fi
 \penalty\@M
\futurelet\@let@token\LT@@nobreakhline}
\def\LT@@nobreakhline{%
\ifx\LT@next\hline
  \global\let\LT@next\@gobble
 \ifx\CT@drsc@\relax
   \gdef\CT@LT@sep{%
     \noalign{\penalty\@M\vskip\doublerulesep}}%
 \else
   \gdef\CT@LT@sep{%
     \multispan\LT@cols{%
       \CT@drsc@\leaders\hrule\@height\doublerulesep\hfill}\cr}%
 \fi
\else
 \global\let\LT@next\empty
 \gdef\CT@LT@sep{%
   \noalign{\penalty\@M\vskip-\arrayrulewidth}}%
\fi
\ifnum0=`{\fi}%
\multispan\LT@cols
 {\CT@arc@\leaders\hrule\@height\arrayrulewidth\hfill}\cr
\CT@LT@sep
\multispan\LT@cols
 {\CT@arc@\leaders\hrule\@height\arrayrulewidth\hfill}\cr
\noalign{\penalty\@M}%
\LT@next}

I think \hline* would be even better than nobreakhline for consistency with \\*

@chrisaga chrisaga changed the title longtable : provide a non breakable \line longtable : provide a non breakable \hline Jun 21, 2024
@davidcarlisle
Copy link
Member

hmm yes \hline* would be sort of natural but the problem is that \hline is looking ahead for another \hline so the * would complicate the parsing. The extra code needed wouldn't be impossible, there is rather more token memory now than in 1990:-) but would still lead to things like \hline*\hline or \hline\hline* or \hline*\hline* and I'd need to decide if they were all legal, and if they all meant the same thing.

@davidcarlisle
Copy link
Member

An alternative would be to not introduce a new \hline option but to directly address the problem in the example, arrange that an \hline or \hline\hline following \\* don't allow a page break. (I don't have code for that immediately available but must be possible in theory and might be a better interface.

@FrankMittelbach
Copy link
Member

I agree, the latter would be the more natural interface. Given that \hline is looking for another \hline it would see the following \\and so could look further for * and act depending on what it finds without too much problems.

@car222222
Copy link
Contributor

@FrankMittelbach But my understanding is that the \\* would be before the lines.

@car222222
Copy link
Contributor

It is probably safer (more logical?) not to mix up the use of \\* with breaks after hlines -- separation of concerns is usually optimal!

@FrankMittelbach
Copy link
Member

yes, my bad to remember the order incorrectly. But that means that somehting like \\* \hline \hline* would make sense with the meaning "if there is a break break between the two lines" as well as \\* \hline* \hline meaning "allow a break only after the double line"

@chrisaga
Copy link
Author

An alternative would be to not introduce a new \hline option but to directly address the problem in the example, arrange that an \hline or \hline\hline following \\* don't allow a page break. (I don't have code for that immediately available but must be possible in theory and might be a better interface.

It would be great! It actually wrote

\\*
\hline

in the first place, hoping it would do what I wanted. Then I figured out that \hline re-enabled the page break disabled by \\*.
Honestly I suggested \hline* because I thought that it was more "elegant" than \nobreakhline but I am perfectly happy with the later.

Copy link

This issue has been automatically marked as stale because it has not had recent activity.

Copy link

This issue has been automatically marked as stale because it has not had recent activity.

@github-actions github-actions bot added the stale label Oct 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants