I know questions about grid typesetting have been asked before, and some packages (grid
, gridpos
) exist. The scenario I have at the moment is simpler than that, and is mostly a question about elastic lengths. I'm not claiming the result is excellent typography, but I'm curious whether and how it could be done 🙂
In typesetting my thesis, I have a page where \textheight
is an exact multiple of \baselineskip
, so I can fit exactly 34 lines of text into the page. The section and subsection commands are defined by the style file as
\renewcommand\section{\@startsection {section}{1}{\z@}%
{-3.5ex \@plus -1ex \@minus -.2ex}%
{2.3ex \@plus.2ex}%
{\def\baselinestretch{1.0}\reset@font\normalsize\bfseries\slshape}}
\renewcommand\subsection{\@startsection{subsection}{2}{\z@}%
{-3.25ex\@plus -1ex \@minus -.2ex}%
{1.5ex \@plus .2ex}%
{\reset@font\normalsize\mdseries\itshape}}
(Which as far as I can tell have been copied and pasted from elsewhere on the web without any particular rhyme or reason. Why should the space around section headings have anything to do with the x-height of the font?)
On pages that have 0 or 2+ section headings, there is enough stretchability around the headings to account for their non-integral-multiple-of-\baselineskip
heights. On pages that have 1 section heading in the middle of the page, there is again enough stretchability before and after the heading. But on pages where the section heading is the first thing in the page, the before-heading space is elided, along with its stretchability, and I get underfull \vbox
es.
My question is, is there a way to change the spaces in these definitions so that when a section heading starts a page, it skips a full line, but when it is in the middle of the page, it uses these smaller stretchabilities? A manual solution is to insert \vspace*{0pt plus 0.5\baselineskip}
at each problematic section heading, which lets TeX "round up" to the next nearest line, but if I simply insert that spacing everywhere, then TeX will use that stretch even when it doesn't need to… I tried looking at the internal definitions of \@startsection
and \@ssect
, but I don't see any way for them to detect when the before-space is elided from the page.
Best Answer
As you have noted,
ex
(andem
) lengths are relative to the currently used fonts. The reason for this depends on the application. In your instance it makes sense using a font size-specific length, since the typesetting the sectional heading may be different depending on whether the document is processed using10pt
,11pt
or12pt
(or, for that matter, any other font size) as\normalfont
. For example, using absolute lengths (likept
,bp
orpc
, for example) may cause the gap between section headings and text to seem too small, or too large, if the font size is changed. The example below a font-based skip of1em
between a pseudo-section heading is replaced by a fixed-width11.5pt
skip (in10pt
,1em
or roughly11.5pt
, see the TeX Book, p 60):Since I am not entirely sure of your sectional intent (that almost came out wrong), here's a suggestion when it comes to page-breaking woes. The
needspace
package provides\needspace{<len>}
that issues a\break
if there is less than<len>
space available on the page. And, the code is not very complicated. Here is a modified version, now taking 3 arguments for the sake of this discussion:It would be possible to redefine
\section
so as to use the above\needspace
and condition on the type of\@startsection
that should be called.