I'm typesetting a text with sections separated by the \vspace{1em}
(sections have no titles). Sometimes the end of section coincides with the end of page. In this case the reader cannot see the end of section separator.
I want to implement the following solution of this problem.
When the new section ends at the end of the page, I want to replace the \vspace
separator with, say, three stars ***
. How can I do this?
-
your sections are not numbered ? please add compilable small example.– user4686Commented Feb 22, 2016 at 18:31
2 Answers
The memoir
class provides for this kind of anonymous division. The \plainfancybreak
macro inserts some blank space between paragraphs in the middle of a page or something more fancy if the break occurs at the start or end of a page. Please read the manual for details on how to use this (texdoc memoir
section 6.7 Fancy Anonymous Breaks, pp 108 -- 110)
The following might not be fool-proof (depending on your document construction), but it's worth a try:
\documentclass{article}
\usepackage{lipsum}\sloppy% Just for this example
% Taken from http://tex.stackexchange.com/a/36726/5764
% Taken from the needspace package (http://ctan.org/pkg/needspace)
\makeatletter
% \needspace{<len>}{<less than len>}{<more than len>}
\newcommand{\needspace}[3]{\par \penalty-100\begingroup
\setlength{\dimen@}{#1}%
\dimen@ii\pagegoal \advance\dimen@ii-\pagetotal
\ifdim \dimen@>\dimen@ii
#3
\else
#2
\fi\endgroup}
\makeatother
\renewcommand{\section}{%
\unskip\par
\needspace{3\baselineskip}
{\vspace{1em}}
{\newpage\noindent\makebox[\linewidth]{* \quad * \quad *}%
\par}%
}
\begin{document}
\section\lipsum[1-4]
\section\lipsum[1-4]
\section\lipsum[1-4]
\section\lipsum[1-4]
\section\lipsum[1-4]
\section\lipsum[1-4]
\section\lipsum[1-4]
\end{document}
Some code from needspace
checks for the available space on the current page, and conditions on what to output if there's (not) enough space.
The following uses the footer to insert a "\section
break" that coincides with a page break:
\documentclass{article}
\usepackage{lipsum}\sloppy% Just for this example
\usepackage{fancyhdr}
% Taken from http://tex.stackexchange.com/a/36726/5764
% Taken from the needspace package (http://ctan.org/pkg/needspace)
\makeatletter
% \needspace{<len>}{<less than len>}{<more than len>}
\newcommand{\needspace}[3]{\par \penalty-100\begingroup
\setlength{\dimen@}{#1}%
\dimen@ii\pagegoal \advance\dimen@ii-\pagetotal
\ifdim \dimen@>\dimen@ii
#3
\else
#2
\fi\endgroup}
\makeatother
\renewcommand{\section}{%
\unskip\par
\needspace{3\baselineskip}
{\vspace{1em}}
{\renewcommand{\sectionend}{* \quad * \quad *}%
\newpage
\renewcommand{\sectionend}{}}%
}
\newcommand{\sectionend}{}
\pagestyle{fancy}
\fancyhf{}% Clear fancy header/footer
\renewcommand{\headrulewidth}{0pt}% No header rule
\fancyfoot[C]{\begin{tabular}[b]{@{}c@{}} \sectionend \\ \thepage \end{tabular}}
\begin{document}
\section\lipsum[1-4]
\section\lipsum[1-4]
\section\lipsum[1-4]
\section\lipsum[1-4]
\section\lipsum[1-4]
\section\lipsum[1-4]
\section\lipsum[1-4]
\end{document}
-
This code places the stars at the beginning of the next page. Can I put the stars at the end of the previous page?– bcpCommented Feb 26, 2016 at 10:06
-
1@bcp: That's a bit more difficult, unless you change your input to using something like
\begin{chunk} <some text> \end{chunk}
, so one could tap into\end{chunk}
. Regardless, it's far more difficult to skip back to the bottom of the previous paragraph after it's already been set. One could add content to the footer, perhaps... I'll see if I can figure something out...– Werner ♦Commented Feb 26, 2016 at 17:43 -
1