[Tex/LaTex] How to remove space before \chapter

chaptersspacing

I am trying to customize the chapter style in the report class :

  • Remove the blank page generated between chapter : Done with the
    etoolbox package : \patchcmd{\chapter}{\if@openright\cleardoublepage\else\clearpage\fi}{}{}{}
  • Remove the "Chapter Number Something" : Done with the titlesec package : \titleformat{\chapter}[display]{\normalfont\bfseries}}{}{0pt}{\Huge}
  • And here is where I am confused, when I want to remove the space before the chapter name.
    I tried with titlesec \titlespacing{\chapter}{0pt}{0pt}{0pt} but there is still space before the chaptername and I also tried with negative values in the second curly brackets but the text is writing other itself.

I would like the chapter name to be at the top of the page and not so much blank space for the other chapters before and after it.
If the top margin is set at 2.5cm, I would like the chatper name to be at 2.5cm

enter image description here

Here is my code :

\documentclass[12pt,oneside]{report}
\usepackage[top=2.5cm, bottom=2.5cm, left=2.5cm, right=2.5cm]{geometry}

\usepackage{etoolbox}
\makeatletter
\patchcmd{\chapter}{\if@openright\cleardoublepage\else\clearpage\fi}{}{}{}
\makeatother

\usepackage{titlesec}
\titleformat{\chapter}[display]
    {\normalfont\bfseries}{}{0pt}{\Huge}

\titlespacing{\chapter}{0pt}{-50pt}{0pt}

\begin{document}

\chapter{My chapter}
lol

\chapter{Another chapter}
lol

\end{document}

Best Answer

Firstly, you don't actually need to patch \chapter, since openright is not the default for report. If you use a document class where it is, you can use the option openany to prevent empty pages between chapters.

Now, there are several possibilities to tackle this:


You could use KOMA-Script, which provides many macros that allow an easier modification of the layout than the standard classes:

\documentclass{scrreprt}

% makes the page borders visible
\usepackage{showframe}

\renewcommand*\chapterformat{}
\renewcommand*\chapterheadstartvskip{}

\begin{document}

\chapter{My chapter}
lol

\chapter{Another chapter}
lol


\end{document}

First MWE output


If you prefer working with report and titlesec, the correct syntax of \titlespacing is

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

or

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

To get rid of some of the space above the chapter title, you can drop the display option of \titleformat. I did however not manage to get rid of all the space without some hacking of internal commands. If we do that, we can just as well do it without titlesec:


You could redefine \@makechapterhead which typesets the chapter title. Here I took the default definition and commented everything you don't want.

\documentclass{report}

% makes the page borders visible
\usepackage{showframe}

\makeatletter
    \renewcommand*\@makechapterhead[1]{%
%       \vspace*{50\p@}%
        {%
            \parindent\z@\raggedright\normalfont
%           \ifnum\c@secnumdepth>\m@ne
%               \huge\bfseries\@chapapp\space\thechapter\par
%               \nobreak\vskip 20\p@
%           \fi
%           \interlinepenalty\@M
            \Huge\bfseries
            #1\par
            \nobreak\vskip 40\p@
        }
    }
\makeatother

\begin{document}

\chapter{My chapter}
lol

\chapter{Another chapter}
lol

\end{document}

Second MWE output