1

After editing the title of a chapter with package titlesec and the command \titleformat, I realized that the spacing between lines is changed when a figure environment using the option [H] from the package float is used. I can replace [H] for [h] to let LaTeX displace the figure wherever it finds better, or add a \clearpage to return the line spacing in the title back to the original one.

I like to use [H] while editing to avoid LaTeX replacing figures and I still don't know the final version of the text, or even the figure size. So:

  1. What should I do to avoid the undesired line spacing in title?
  2. What are good methods to control the line spacing of the text when floats are floating around?

I checked titlesec formatting but I didn't seem to have any effect.

A MWE follows:

\documentclass{book}
\usepackage[margin=2cm]{geometry}
\usepackage{lipsum}
\usepackage{graphicx}
\usepackage{float}

\usepackage{titlesec}
\titleformat{\chapter}[display]
{\vspace{-2.5cm}\normalfont\Large\filcenter\bfseries} % \sffamily
{\titlerule[1.5pt]%
  \vspace{5pt}%
  {\Huge{\chaptertitlename} {\thechapter}}
}
{2pt}
{\titlerule
  \vspace{2pt}%
  \Huge\bfseries
  \vspace{5pt}
}
[{\titlerule[1.5pt]}\vspace{-20pt}]
% I don't know how and if titlespacing would help
%\titlespacing*{\chapter}{5pt}{0.7in}{20pt}

\begin{document}
\chapter{title}

\lipsum[1-4]

% \clearpage
\begin{figure}[H] % [h]
  \includegraphics[width = 0.9\linewidth]{example-image-a}
  \caption{Caption}
\end{figure}

\end{document}

And the figures:

enter image description here

enter image description here

enter image description here

1
  • Try adding \raggedbottom to your preamble.
    – leandriis
    Aug 12, 2020 at 6:06

1 Answer 1

2

You should never use [H]. Anyway, the issue can be somewhat cured by setting \parskip to zero inside the chapter title.

\documentclass{book}
\usepackage[margin=2cm]{geometry}
\usepackage{lipsum}
\usepackage{graphicx}
\usepackage{float}

\usepackage{titlesec}
\titleformat{\chapter}[display]
{\setlength{\parskip}{0pt}\normalfont\Large\filcenter\bfseries} % \sffamily
{\titlerule[1.5pt]%
  \vspace{5pt}%
  {\Huge{\chaptertitlename} {\thechapter}}
}
{2pt}
{\titlerule
  \vspace{2pt}%
  \Huge\bfseries
  \vspace{5pt}
}
[{\titlerule[1.5pt]}]
% I don't know how and if titlespacing would help
\titlespacing*{\chapter}{0pt}{0pt}{20pt} % fix the 20pt to suit

\begin{document}
\chapter{title}

\lipsum[1-4]

\begin{figure}[H] % [h]
  \includegraphics[width = 0.9\linewidth]{example-image-a}
  \caption{Caption}
\end{figure}

\end{document}

I removed the “eye-computed” negative vertical space and added the \titlespacing instruction to get the precise result.

enter image description here

The stretch is only between paragraphs in the text and not in the chapter title. The result is disastrous anyway, but it's caused by [H].

\documentclass{book}
\usepackage[margin=2cm]{geometry}
\usepackage{lipsum}
\usepackage{graphicx}

\usepackage{titlesec}
\titleformat{\chapter}[display]
{\setlength{\parskip}{0pt}\normalfont\Large\filcenter\bfseries} % \sffamily
{\titlerule[1.5pt]%
  \vspace{5pt}%
  {\Huge{\chaptertitlename} {\thechapter}}
}
{2pt}
{\titlerule
  \vspace{2pt}%
  \Huge\bfseries
  \vspace{5pt}
}
[{\titlerule[1.5pt]}]
% I don't know how and if titlespacing would help
\titlespacing*{\chapter}{0pt}{0pt}{20pt}% fix the 20pt to suit

\begin{document}
\chapter{title}

\lipsum[1-4]

\begin{figure}[!htp]
  \centering
  \includegraphics[width = 0.8\linewidth]{example-image-a}
  \caption{Caption}
\end{figure}

\lipsum[1-20]

\end{document}

enter image description here

You must log in to answer this question.

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