As you have noted, ex
(and em
) 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 using 10pt
, 11pt
or 12pt
(or, for that matter, any other font size) as \normalfont
. For example, using absolute lengths (like pt
, bp
or pc
, 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 of 1em
between a pseudo-section heading is replaced by a fixed-width 11.5pt
skip (in 10pt
, 1em
or roughly 11.5pt
, see the TeX Book, p 60):
\documentclass{article}
\begin{document}
\bfseries% For bold font
{\normalfont Font-based skip of \verb!1em!} \par \medskip
\newcommand{\myskip}{\unskip\rule[0.5ex]{1em}{1pt}\ignorespaces}
{\normalsize 1 \myskip A section \par}%
{\large 1 \myskip A section \par}%
{\Large 1 \myskip A section \par}%
{\LARGE 1 \myskip A section \par}%
{\Huge 1 \myskip A section \par}%
\bigskip \hrulefill \bigskip
{\normalfont Fixed-width skip of \verb!11.5pt!} \par \medskip
\renewcommand{\myskip}{\unskip\rule[0.5ex]{11.5pt}{1pt}\ignorespaces}
{\normalsize 1 \myskip A section \par}%
{\large 1 \myskip A section \par}%
{\Large 1 \myskip A section \par}%
{\LARGE 1 \myskip A section \par}%
{\Huge 1 \myskip A section \par}%
\end{document}
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:
\makeatletter
% \needspace{<len>}{<NOT enough space>}{<enough space>}
\newcommand{\needspace}[3]{\par \penalty-100\begingroup
\setlength{\dimen@}{#1}%
\dimen@ii\pagegoal \advance\dimen@ii-\pagetotal
\ifdim \dimen@>\dimen@ii% execute the following if there IS NOT enough space on page
\ifdim \dimen@ii>\z@
\vfil
\fi
\break
#2% <NOT enough space>
\else% execute the following if there IS enough space on page
#3% <enough space>
\fi\endgroup}
\makeatother
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.
The basic answer is that you have to make all your display objects fit into multiples of your grid, e.g., headings, display equations, etc. need to be preprocessed and boxed so that they fit the grid and similarly floats and footnotes have to be adjusted to honor the space requirements. There are a bunch of packages out there who are making an attempt at this, e.g., grid.sty
from River Valley or ltxgrid
from RevTeX and even if you do not want to use those, it might be worthwhile to look at what they do and how.
One option for something like display environments is to typeset them into a \vbox
of column width and then measure the the amount of vertical space they occupy. Then add on top and below whatever is needed to get to the multiple of the grid. The tricky part then is to set \prevdepth
properly so that the next line of text still aligns on the grid. Another problem is that you may want to split such material across the page. Using \unvbox
might be an option but only ensure that you do not end up with stretchable glue that may break your grid.
Playing around with \lineskiplimit
is possible and to some extend useful, but if set to a negative value for paragraphs it means that lines can overprint (and TeX will not detect this for you).
Best Answer
Your requirement 2 is very difficult in latex (and a frequent topic of discussion when people get together to talk about future versions). As well as the grid package there is the gridset package. The grid package tries to make all vertical spaces a multiple of the baselineskip (or pairs of pre-/post-spacing that sum to a multiple of baselineskip), and removes vertical glue. The gridset package tries to "reset" the text back onto the grid after an odd-sized equation or floating figure or table, but it doesn't necessarily do it in the most aesthetic way, and it may take many compilation passes before convergence.
For your requirement 1, check out the flowfram package. It seems to do what you want.