# Why does section command cause large vertical space before only at top of page?

%
\documentclass{book} %
%
\usepackage[fleqn]{amsmath} %
\usepackage{amsthm,amssymb} %
\usepackage[explicit]{titlesec} %
\usepackage{titletoc} %
\usepackage[english]{babel} %
\usepackage{txfonts} %
\usepackage{xcolor}
\usepackage{colortbl} %

\usepackage[format=plain,listformat=empty,labelsep=space,position=below,width=\linewidth,labelfont={normal},font={normal}]{caption} %

\usepackage[margin=6pt,justification=raggedright]{subcaption} %

\usepackage[verbose]{geometry} %
\usepackage[a4,frame,center]{crop}
\usepackage[most]{tcolorbox}
\usepackage{bookmark} %
%
\setlength{\unitlength}{1mm} %
%
\paperwidth=170mm
\paperheight=240mm
\setlength{\textwidth}{132mm}

\definecolor{ThemeColour}{rgb}{0.45,0.00,0.45} %
\definecolor{DarkGrey}{rgb}{0.92,0.92,0.92}
\definecolor{DarkRed}{rgb}{0.45,0.00,0.00} %
\definecolor{LightCream}{rgb}{1.00,1.00,0.90} %

\newcommand\Hrule{\noindent\color{ThemeColour}{\rule{\linewidth}{3pt}}} %
\newcommand\hseprule{\color{DarkRed}{\rule{\linewidth}{0.7pt}}} %

\titleformat{\chapter}[display]
{\color{ThemeColour}\bfseries\itshape\fontsize{30}{30}\selectfont} %
{\Hrule\vspace*{6pt}\\ {\color{black}\,\chaptername\hspace{8pt}\normalfont\fontsize{42}{45}\selectfont{\thechapter}}} %
{0pt}{\bfseries\normalfont\fontsize{15}{18}\selectfont{#1} \\ \vspace*{-9pt}\Hrule}[\vspace{18pt}] %

\titlespacing{\chapter}{0pt}{12pt}{6pt}[0pt] %
\renewcommand{\thechapter}{\arabic{chapter}} %

\newtcolorbox{sectionbox}[2][]{boxsep=4.2pt,boxrule=1.2pt,arc=3pt,outer arc=3.2pt,width=\linewidth,
coltitle=white,colbacktitle=ThemeColour,after=\hfill,colframe=black,colback=DarkGrey,title={#2},fonttitle=\bfseries,#1}

\titleformat{\section} %
{\normalfont\bfseries\itshape\fontsize{12}{14}\selectfont}
{}{0pt}
{\begin{sectionbox}
{\fontsize{14}{16}\selectfont{Section\hspace{5.6pt}\thetitle}}{#1}
\end{sectionbox}}

\titlespacing{\section}{0pt}{10pt}{6pt}[0pt] % 0, 10, 6, 0
\renewcommand{\thesection}{\arabic{section}} % make-up of number
%
\def\figtab{\kern 0.8pt}

\addto\captionsenglish{ % this seems to work
\renewcommand{\figurename}{Fig\hspace{0.7pt}.} %
\renewcommand{\thefigure}{\thechapter{\figtab.\figtab}\arabic{figure}} % good
\renewcommand{\thesubfigure}{\hspace{0.5pt}\alph{subfigure}\hspace{0.4pt}} %
}

\begin{document}

\pagestyle{plain}

\chapter{Introduction to number}

\section{Section one - only small gap above (ok)}

\section{Section two - directly follows section one - gap ok}

\section{Section three - directly follows section two}

\clearpage

\section{Section four - shows 40mm gap at the top of the page (far too much)}

\section{Section five - directly follows section four - gap ok}

\section{Section six} \vspace{50mm}

\noindent Even though the page is nearly full.\vspace{50mm}

\noindent Even though the page is nearly full.

\end{document}

• Thanks, that's revealed a lot. I added another page with an ordinary paragraph on it and the section is 8mm lower than that ordinary text. Can I reduce that to zero? Also, what are those empty frames sticking out to the left or right, please? – keith77777 Sep 25 '15 at 11:33

You have to load geometry before crop, with option driver=none. Additionally, I incorporated your size specifications as options to the geometry package, and added the options showframe and showcrop, to display what really happens.

To remove all vertical spacing at the top of a page, I added the nobeforeafter option to the \tcolorbox used in \titleformat{\section}, so the spacing is entirely managed by \titlespacing{\section}.

%
\documentclass[a4paper]{book} %
%
\usepackage[fleqn]{amsmath} %
\usepackage{amsthm,amssymb} %
\usepackage[explicit]{titlesec} %
\usepackage{titletoc} %
\usepackage[english]{babel} %
\usepackage{txfonts} %
\usepackage{xcolor}
\usepackage{colortbl} %

\usepackage[format=plain,listformat=empty,labelsep=space,position=below,width=\linewidth, labelfont={normal},font={normal}]{caption} %

\usepackage[margin=6pt,justification=raggedright]{subcaption} %

\usepackage[paperwidth=170mm, paperheight=240mm, textwidth=132mm,verbose, driver=none, showcrop, showframe]{geometry}
%
\usepackage[a4,frame,center]{crop}
\usepackage[most]{tcolorbox}
\usepackage{bookmark} % %
%
\setlength{\unitlength}{1mm} %

\definecolor{ThemeColour}{rgb}{0.45,0.00,0.45} %
\definecolor{DarkGrey}{rgb}{0.92,0.92,0.92}
\definecolor{DarkRed}{rgb}{0.45,0.00,0.00} %
\definecolor{LightCream}{rgb}{1.00,1.00,0.90} %

\newcommand\Hrule{\noindent\color{ThemeColour}{\rule{\linewidth}{3pt}}} %
\newcommand\hseprule{\color{DarkRed}{\rule{\linewidth}{0.7pt}}} %

\titleformat{\chapter}[display]
{\color{ThemeColour}\bfseries\itshape\fontsize{30}{30}\selectfont} %
{\Hrule\vspace*{6pt}\\ {\color{black}\,\chaptername\hspace{8pt}\normalfont\fontsize{42}{45}\selectfont{\thechapter}}} %
{0pt}{\bfseries\normalfont\fontsize{15}{18}\selectfont{#1} \\ \vspace*{-9pt}\Hrule}[\vspace{18pt}] %

\titlespacing{\chapter}{0pt}{12pt}{6pt}[0pt] %
\renewcommand{\thechapter}{\arabic{chapter}} %

\newtcolorbox{sectionbox}[2][]{nobeforeafter, boxsep=4.2pt,boxrule=1.2pt,arc=3pt,outer arc=3.2pt,width=\linewidth,
coltitle=white,colbacktitle=ThemeColour,after=\hfill,colframe=black,colback=DarkGrey,title={#2},fonttitle=\bfseries,#1}

\titleformat{\section} %
{\normalfont\bfseries\itshape\fontsize{12}{14}\selectfont}
{}{0pt}
{\begin{sectionbox}
{\fontsize{14}{16}\selectfont{Section\hspace{5.6pt}\thetitle}}{#1}
\end{sectionbox}}

\titlespacing{\section}{0pt}{10pt}{6pt}[0pt] % 0, 10, 6, 0
\renewcommand{\thesection}{\arabic{section}} % make-up of number
%
\def\figtab{\kern 0.8pt}

\addto\captionsenglish{ % this seems to work
\renewcommand{\figurename}{Fig\hspace{0.7pt}.} %
\renewcommand{\thefigure}{\thechapter{\figtab.\figtab}\arabic{figure}} % good
\renewcommand{\thesubfigure}{\hspace{0.5pt}\alph{subfigure}\hspace{0.4pt}} %
}
\raggedbottom

\begin{document}

\pagestyle{plain}

\chapter{Introduction to number}

\section{Section one - only small gap above (ok)}

\section{Section two - directly follows section one - gap ok}

\section{Section three - directly follows section two}

\clearpage

\section{Section four - shows 40mm gap at the top of the page (far too much)}

\section{Section five - directly follows section four - gap ok}

\section{Section six} \vspace{50mm}

\noindent Even though the page is nearly full.\vspace{50mm}

\noindent Even though the page is nearly full.

\end{document}


• Many thanks for your detailed answer, Bernard. – keith77777 Sep 25 '15 at 13:10
• Bernard, it has since occurred to me... what were those empty frames sticking out to the left or right in my original tex file, please? – keith77777 Sep 25 '15 at 14:55
• The empty frames remain in my full tex file, and I don't think they should. – keith77777 Sep 25 '15 at 14:56
• Bernard - problem solved. I had \usepackage{showframe} included twice. Thanks. – keith77777 Sep 25 '15 at 16:07