1

I want remove the white space before the chapter name, however, the white space is different in different sections of the document.

\titlespacing*{\chapter}{0pt}{-40pt}{0pt}

enter image description here

enter image description here

\titlespacing*{\chapter}{-20pt}{-40pt}{0pt}

enter image description here

enter image description here

Below is a short working example that shows what I mean.

\documentclass{report}
\usepackage[utf8]{inputenc}
\usepackage{fancyhdr}
\usepackage[nottoc]{tocbibind}
\usepackage{titlesec}
\usepackage{lipsum}

\titleformat{\chapter}[hang]
{\normalfont\huge\bfseries}{}{20pt}{\Huge}   
\titlespacing*{\chapter}{0pt}{-40pt}{0pt} % This is the line which I am using. I don't know if it is the right one to use.

\pagestyle{fancy}
\fancyhf{}
\rhead{Share\LaTeX}
\lhead{Guides and tutorials}
\rfoot{Page \thepage}
\begin{document}
\tableofcontents
\thispagestyle{fancy}

\clearpage

\chapter{Specs}
\thispagestyle{fancy}
\section{Introduction}
\lipsum
\end{document}

I would appreciate any help in fixing this problem

1 Answer 1

1

The titlesec documentation provides the following format for \titleformat (see section 3.1 Format):

\titleformat{<command>}
  [<shape>]
  {<format>}
  {<label>}
  {<sep>}
  {<before-code>}
  [<after-code>]

where

<sep> is the horizontal separation between label and title body and must be a length (it must not be empty). This space is vertical in display <shape>; in frame it is the distance from text to frame. Both <label> and <sep> are ignored in starred versions of sectioning commands. If you are using picture and the like, set this parameter to 0pt.

Your Contents chapter is set using \chapter*, and is therefore without number. Since you're not setting numbers for numbered chapters (<label> is left empty), you'll have to use a 0pt <sep>:

enter image description here

\documentclass{report}

\usepackage{titlesec}
\usepackage{lipsum}

\titleformat{\chapter}[hang]
  {\normalfont\huge\bfseries}{}{0pt}{\Huge}
\titlespacing*{\chapter}{0pt}{-40pt}{0pt}

\begin{document}

\tableofcontents

\clearpage

\chapter{Specs}
\section{Introduction}
\lipsum

\end{document}
0

You must log in to answer this question.

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