# Extremely weird formatting of text in section

\documentclass[a4paper, 11pt]{book}

% Packages
\usepackage[utf8]{inputenc}
\usepackage{graphicx} % For images
\usepackage{titlesec} % For adjusting title spacing
\usepackage{biblatex} % Reference Manager
\usepackage{enumitem} % To itemize the symbols and abbreviations list
\usepackage{etoolbox} % To help remove numbering from inputted pages in frontmatter
\usepackage{lipsum}
\usepackage{setspace}
% Environments

% Extra Declarations
\let\cleardoublepage=\clearpage % Clear second page automatically set by book class

% Set itemized format for symbols and abbreviations
\newlist{abbrv}{itemize}{1}
\setlist[abbrv,1]{label=,labelwidth=1in,align=parleft,itemsep=0.1\baselineskip,leftmargin=!}

% To shift margins of even numbered pages to the left
\let\tmp\oddsidemargin
\let\evensidemargin\oddsidemargin
\let\evensidemargin\tmp
\reversemarginpar

% Increase right margin length by removing margin notes and increasing width
\marginparwidth 0pt % set width of margin notes to zero
\marginparsep 0pt % set distance between margin notes and body to zero
\textwidth \dimexpr \pdfpagewidth -2\oddsidemargin -2in % increase body width

%%%%%%%%%% Document Starts Here %%%%%%%%%%%%%%%%%%
\begin{document}
\frontmatter %Tex files that were inputted are set formats by my University

\mainmatter
%\pagestyle{plain} - default setting of mainmatter

\chapter{Materials and Methods}
\onehalfspacing

In this experiment, the subjects were asked to perform a task based on four movement indicators. These four indicators are presented on a screen. The indicators represent four directions - forward, backward, left and right which will be presented in sequence. The sequence of movement the four movement indicators will be random each trial. The experiment start with the subject looking at a fixation target: a solid dot at the centre of the screen, the dot will remain on the screen for the whole experiment to prevent eye movement. To start the experiment the subject will press a button soon after which the four indicators will be presented on the screen one after the other, every 500ms. After the fourth indication is displayed, the fourth auditory cue is generated after 200ms and for a duration of 200ms to indicate the subject to start planning the movements, a second auditory cue is generated at a random interval between 500ms t0 850ms after the first cue is completed, again for a duration of 200ms.

The sound used represents the note A and has an octave = 4 and stereo = -1. The second cue is indicates the subject to initiate the first foot movement. Once the first foot movement is completed, which is detected by the foot interface, the first and second auditory cues are generated and the the second foot movement is performed in accordance to the sequence displayed by the indicators. This is repeated for the 4 moves in total and this constitutes a single trial. There are a total of 200 trials, 2 min breaks are given every 6 trials in order to ensure that the participant does not get physically or mentally exhausted. Out of the 200 trials there will be 10 different patterns of sequences each repeated 20 times.

\section{Recruitment}
\lipsum[2]
\backmatter

\end{document}


In the section " Experimental paradigm", if it is run right now there is considerable space between the section header and first para & between the first para and the second para as shown below:

Now if I add some text - about 2 to 3 lines anywhere in the second or first paragraph the formatting goes back to how it's supposed to look. It seems like some sort of compression effect that's happening, but I don't understand why and how this is going on about when dimensions are more or less fixed. I tried using setspace and titlesec packages to format the distances but nothing worked. Would really appreciate some help.

EDIT:

\raggedbottom worked. Another solution I found was using \clearpage.

One more question I have is that when I use any of the two solutions why doesn't the next section move up to fill the remaining space in that page?

• In book (or actually in twopage mode), LaTeX by default tries to set everything flush bottom, so that every page ends on the same height, which tends to look better for double pages. If you don't like it you can use \raggedbottom to deactivate it. – Skillmon Oct 14 '19 at 5:54
• Welcome to TeX.SE... Mentioned issue happened because of the package setspace and \onehalfspacing, \parskip value was defined as fluxy in this package, so only it happend... – MadyYuvi Oct 14 '19 at 6:07
• @Skillmon Where do I place the \ruggedbottom, i tried placing it after the section and before \begin{document} but none of them worked. You also mentioned that latex by default makes every page at the same height, i'm a bit confused about this as there is a defined height from the bottom so, without this default nature of book wouldn't the same happen. Also why does the text compress? – Roshan Oct 14 '19 at 6:13
• @MadyYuvi I removed setspace, \onehapfspacing but I got the same output. What you said makes sense but it doesn't work. – Roshan Oct 14 '19 at 6:14
• The reason I didn't recommend using \clearpage before the \section is, that this results in inconsistent spacing, normally a new section starts on the same page, or on the next with a flushed page before it. Now you'd get one single section that starts on a new page without a flushed page before it, like only chapters and parts do by default. So either I'd put the whole thing in \raggedbottom or nothing (or just the appendix) and not just a single page. – Skillmon Oct 14 '19 at 7:43