4

Consider the code below. The distance between the chapter title and the baseline of the following text is font dependent. I assume that there is a glue between the chapter title and the top of the first row. When I insert a \strut at the beginning of the paragraph, the distance seems to be fixed (which makes sense, as the strut is always the same, regardless of the current font.

How can I fix the problem, that the distance between the chapter title and the base line of the first text row is font dependent?

Can I insert a \strut at every par? Can I say "x pt distance to then next baseline"?

enter image description here enter image description here

\documentclass[11pt]{book}
\usepackage{lipsum,xcolor}
\usepackage{mathpazo}
% \usepackage{lua-visual-debug}
\usepackage[showframe]{geometry}

\usepackage{titlesec}
\titleformat{\chapter}[hang]{\fontsize{20bp}{20bp}\selectfont}{\thechapter}{1ex minus .1ex}{}

% without strut at the beginning of first paragraph
% \titlespacing*{\chapter}{0cm}{\dimexpr -\topskip }{6.5bp}[0pt] % mathpazo
% \titlespacing*{\chapter}{0cm}{\dimexpr -\topskip }{6.9bp}[0pt] % mathptmx

% with strut at the begining of the first paragraph
\titlespacing*{\chapter}{0cm}{\dimexpr -\topskip }{6bp}[0pt]   % mathptmx + mathpazo

\renewcommand\normalsize{\fontsize{9bp}{10bp}\selectfont}


\parskip0pt


\usepackage{atbegshi,picture}
\makeatletter
\AtBeginShipout{%
  \AtBeginShipoutUpperLeft{%
    \put(\dimexpr
      \ifodd\value{page}\oddsidemargin\else\evensidemargin\fi + 1in\relax,
      -\dimexpr\topmargin + 1in + \headheight + \headsep\relax){%
      \begin{picture}(0,0)%
        \setlength{\unitlength}{10bp}%
        \setlength{\dimen0 }{0pt}%
        \@whiledim\dimen0<\dimexpr\textheight+1sp\relax\do{%
          \put(0,-\dimen0){\color{green}\line(1,0){\textwidth}}%
          \addtolength{\dimen0 }{\unitlength}%
        }%
      \end{picture}%
    }%
  }%
}
\makeatother

\begin{document}
\chapter{Chapter title}
%\strut
\lipsum[1-3]

\end{document}
4
  • The ex depends on the current font; first of all, don't use 1ex to set the spacing.
    – egreg
    Sep 5, 2012 at 9:51
  • @egreg the ex is not the problem here, this is only for the horizontal space for the number (in \titleformat).
    – topskip
    Sep 5, 2012 at 10:02
  • 1
    I think the problem is because titlesec is using a strut in the section header at the large font size but then using the standard baselineskip and zero parskip before the next paragraph (but inserting extra glue) this means that the heading has very large depth and causes \lineskip glue to be inserted, whenever that happens you fall off the grid. I think if you could get titlesec to smash the depth of its heading row so lineskip is never used (and rely on the after-heading glue to ensure that the smashed descender never over prints) then baselineskip rather than lineskip will be used Sep 5, 2012 at 10:18
  • @DavidCarlisle makes sense. I think I have to cook up my own sectioning solution one day (to handle multi line titles as well...)
    – topskip
    Sep 5, 2012 at 10:23

1 Answer 1

3

If the first line of text after the chapter title is not excessively high, this seems to work with all fonts I tried (and that you find commented out)

\documentclass[11pt]{book}
\usepackage{lipsum,xcolor}
%\usepackage{tgschola}
\usepackage{tgtermes}
%\usepackage{mathptmx}
%\usepackage{mathpazo}
% \usepackage{lua-visual-debug}
\usepackage[showframe]{geometry}

\usepackage{titlesec}
\titleformat{\chapter}[hang]{\fontsize{20bp}{20bp}\selectfont}{\thechapter}{1ex minus .1ex}
  {}[\prevdepth0pt]

\titlespacing*{\chapter}{0cm}{\dimexpr -\topskip }{4bp}%[0pt]   % mathptmx + mathpazo

\renewcommand\normalsize{\fontsize{9bp}{10bp}\selectfont}

\parskip0pt
\lineskip=40pt % just for debugging
%\topskip=10bp 

\usepackage{atbegshi,picture}
\makeatletter
\AtBeginShipout{%
  \AtBeginShipoutUpperLeft{%
    \put(\dimexpr
      \ifodd\value{page}\oddsidemargin\else\evensidemargin\fi + 1in\relax,
      -\dimexpr\topmargin + 1in + \headheight + \headsep\relax){%
      \begin{picture}(0,0)%
        \setlength{\unitlength}{10bp}%
        \setlength{\dimen0 }{0pt}%
        \@whiledim\dimen0<\dimexpr\textheight+1sp\relax\do{%
          \put(0,-\dimen0){\color{green}\line(1,0){\textwidth}}%
          \addtolength{\dimen0 }{\unitlength}%
        }%
      \end{picture}%
    }%
  }%
}
\makeatother

\begin{document}
\chapter{Chapter title}
\lipsum[1]

\end{document}

The \prevdepth0pt is meant to cut off the depth of the title line.

However, this can't always work for multiple line chapter titles; it does with Times (either tgtermes or mathptmx) since ascenders and descenders don't sum up to make \lineskip come into action. It doesn't with mathpazo Palatino, try with

\chapter{Chapter title\\on two lines}

which works good with Times, but not with Palatino.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .