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

\nobreak does not work after multicols environment #1005

Open
raphsilva opened this issue Feb 25, 2023 · 1 comment
Open

\nobreak does not work after multicols environment #1005

raphsilva opened this issue Feb 25, 2023 · 1 comment
Assignees
Labels
category tools enhancement long-term issues (or enhancements) that will not be resolved any time soon but should be considered eventually

Comments

@raphsilva
Copy link

Brief outline of the bug

It seems to be never possible to have an element (in the current example, a horizontal rule) at the end of a multicols environment while guaranteeing there is no page break between the text and the element.

In the example here, the \nobreak is respected only if I remove the multicols environment: since I defined widow penalties, the last lines of the text get moved to the next page in case the rule doesn't fit the page (second PDF attached). I believe this would be the expected behavior for columns too.

Minimal example showing the bug

\usepackage{latexbug}
\documentclass[12pt]{article}

\usepackage[paperwidth=15cm, paperheight=20cm, top=2cm, bottom=2cm, left=2.5cm, right=2.5cm]{geometry}
\usepackage{multicol}
\usepackage{lipsum}

\widowpenalties 4 9999 9000 6000 2000
\clubpenalties 4 9999 9000 6000 2000

\newcommand{\formattedsection}[2]{
    \section{#1}
    \begin{multicols}{2}
        #2
    \end{multicols}
    \par
    \nobreak\hrulefill  % SHOULD BE ON THE SAME PAGE
}

\begin{document}

\formattedsection{My Section}{\lipsum[1-2]}

\end{document}

Log file (required) and possibly PDF file

test.log
test.pdf
test.pdf

@raphsilva raphsilva changed the title \nobreak does not work after multicol multicol can't handle widow penalties Feb 27, 2023
@FrankMittelbach FrankMittelbach self-assigned this Mar 28, 2023
@FrankMittelbach FrankMittelbach changed the title multicol can't handle widow penalties \nobreak does not work after multicols environment Mar 28, 2023
@FrankMittelbach
Copy link
Member

@raphsilva your initial title was much closer to the point so I changed it back. \widowpenalties are a functionality of individual paragraphs and this is honored by multicols but what you are after is attaching something to the balanced columns and that does not work as you correctly noticed. But this is by design and will not change or get extended any time soon. Multicol issues the equiv of \par\allowbreak\addvspace{\multicolsep} at the end and this serves two purposes:

  • drop the vertical space if there is no further space available to add a reasonable amount of material
  • ensure that TeX's recent contributions are emptied before certain calulations are done (which is rather technical but necessary)

However, even if that wouldn't be necessary (and one can with a lot of effort program around it) the situation is not that simple. After multicol has done its balancing the resulting columns for a single unbreakable block. If I would allow to add arbitrary further material that is firmly attached, then that plus the extra material would form a unit and if that would be larger than the whole page (as in your example) then what would happen is that TeX would break before the whole thing instead of producing an overfull page. So you would end up with an empty page (or nearly empty page depending on what comes before) --- probably not what you wanted nor expected.

So what would need to happen is that the following material is first measure and taken into account during balancing and the balancing attempt be would need to be abandoned if both together would be too much.

All of that is in principle doable but it goes way beyond the original design and I have right now no inclination to heavily extend mutlicols. When it gets rewritten then for good and not with individual smallish extensions that in the end do not work well together.

So I'm putting that on long-term rather than closing it,but if or when I ever get to do something like this, I don't know.

ps rather than starting the multicol after a section it is better to put the section into the multicol optional argument, because the start too adds an allowed breakpoint

@FrankMittelbach FrankMittelbach added the long-term issues (or enhancements) that will not be resolved any time soon but should be considered eventually label Mar 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category tools enhancement long-term issues (or enhancements) that will not be resolved any time soon but should be considered eventually
Projects
Development

No branches or pull requests

3 participants