1

I have a specific way of displaying Chapter title headings, by placing the chapter title in between two rules. I use titlesec to achieve this. The issue is, the stretch that LaTeX does over each chapter title page may be different and so the text within the rules is not always exactly centred.

MWE below. Chapter 1 title text is centred, almost perfectly, between the rules (as the \titleformat{\chapter} code was written by looking at this first chapter title). However, for Chapter 2, because the text afterwards is now different, the title text is no longer centred. Please disregard the fonts and sizing. It's the best I could manage to show my issue without just copying my entire actual code. I am sure there are many ways to overcome this. Would an environment do it? But could this be incorporated into titlesec?

\documentclass[10pt,a4paper,twoside]{book}

\newcommand\YUGE{\fontsize{38}{45}\selectfont} % creates an even bigger 'YUGE' font size, at 38pt

\usepackage{titlesec}
\titleformat{\chapter}[display]{\sf\YUGE}{Chapter \thechapter}{-5mm}{\rule{4.5in}{1pt}\vspace{-3mm}\\\rm\huge}[\vspace{-9mm}\rule{4.5in}{1pt}]

\usepackage{lipsum}
\usepackage{parskip}
\setlength{\parskip}{1\baselineskip plus2pt minus2pt}

\begin{document}

\chapter{Example Chapter Title}

\lipsum[1-2]

\chapter{Example Chapter Title}

\lipsum

\end{document}
3
  • It would probably be easier to NOT use titlesec. May 15, 2021 at 17:16
  • Please try the updated answer. Change the \parskip value to see how it works. May 16, 2021 at 17:11
  • Problem solved? Jun 8, 2021 at 22:55

1 Answer 1

1

UPDATED

Unfortunately your MWE does not show the stretching problem that occurs in your actual work.

To make the chapter title unaffected by changes in the parskip, use the package parskip (2021-03-14 v2) to set the parskip value between paragraphs.

For example \usepackage[skip=1.0\baselineskip plus 1pt minus 1pt]{parskip}

The package also patches titlesec to avoid \parskip being added before or after display headings, thus avoiding unexpected vertical spaces. See this answer

The \titleformat might be improved and simplified using \titleline[<rule height>] (unless you wanted shorter lines), avoiding the \\ and preventing the parskips inserted by the rules .

The text after the title should not make any difference to the title format or position.

To compare both pages side by side use \documentclass[10pt,a4paper]{report}

z1

\documentclass[10pt,a4paper,twoside]{book}
    
\newcommand\YUGE{\fontsize{38}{45}\selectfont} % creates an even bigger 'YUGE' font size, at 38pt

\usepackage{titlesec}

%%\titleformat{\chapter}[display]
%{\sf\YUGE}
%{Chapter \thechapter}
%{-5mm}
%{\rule{4.5in}{1pt}\vspace{-3mm}\\\rm\huge}
%[\vspace{-9mm}\rule{4.5in}{1pt}]

\titleformat{\chapter}[display]
{\parskip=0pt\sf\YUGE} % format Chapter nn
{\chaptertitlename\ \thechapter}
{10mm} % space below Chapter nn
{\parskip=0pt\rm\huge\titlerule[1.0pt]\vspace*{4pt}} % format title
[\parskip=0pt\vspace*{3pt}\titleline{\titlerule[1.0pt]}] % after title

%%  \titlespacing{command}{left spacing}{before spacing}{after spacing}
\titlespacing*{\chapter}{0em}{2em}{6em}  % added <<<<<<<

\usepackage[skip=1.0\baselineskip  plus 1pt  minus 1pt]{parskip} % <<<<<<<<<<<< changed 

\usepackage{lipsum}
    
\begin{document}
    
    \chapter{Example Chapter Title}
    
    \lipsum[1-2]
    
    \chapter{Example Chapter Title}
    
    \lipsum
    
\end{document}
3
  • I feared someone would say they saw no difference! Thanks for this code. Sadly the problem of stretching still occurs with it in my actual work. A work around would be to just change my paragraphing on the first page of each chapter until the stretch is 'just right' and the chapter title fits nicely. This is not hard to do, but goes against the spirit of LaTeX I'm sure? There must be some way to stop a certain section within the text from being stretched? The issue of stretching, and the sometimes horrendous space you get between paragraphs, is the only thing I dislike about LaTeX.
    – WilldoesR
    May 16, 2021 at 10:33
  • @WilldoesR Unfortunately your MWE does not show the stretching problem that occurs in your actual work. Please see the updated answer. May 16, 2021 at 16:57
  • The \parskip=0pt alone was sufficient and solved my problem. I don't think I had to change anything else in my code. Thank you
    – WilldoesR
    Jun 10, 2021 at 7:52

You must log in to answer this question.

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