I'm among many it seems that is trying to prevent an inappropriate pagebreak. In this case, I'm getting a pagebreak between my section and subsequent subsection. I know if I remove the \hrule
and \hfill
then LaTeX will pull them together, but with the line between, the subsection is orphaned to the next page.
Here's a MWE:
\documentclass{article}
\begin{document}
Lots\\of\\text\\here\\to\\fill\\space\\so\\that\\the\\new\\section\\is\\right\\near\\the\\bottom.\\
Almost\\there.\\
I\\bet\\there's\\a\\better\\way\\to\\do\\this...\\
Hopefully\\someday\\I'll\\know\\how\\but\\for\\now\\I'm\\stuck\\with\\this\\mess.\\
\section*{Section title}
\hrule
\hfill
\subsection*{\underline{Subsection title}}
\end{document}
I don't want a hard-coded \pagebreak
right before the section because the amount of text above it will vary. I tried wrapping all four lines in \begin{samepage}
and \end{samepage}
but it didn't seem to help.
How can I make sure the subsection is not orphaned on the next page?
\hfill
is absent and the whole thing is not straddling the page break, then the subsection is too close to the\hrule
line and it looks ugly. I have the\hrule
line in the first place to make the underline across the whole page under all the section headers. It's aesthetically pleasing to me.