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 withtitlesec
\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
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
, sinceopenright
is not the default forreport
. If you use a document class where it is, you can use the optionopenany
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:
If you prefer working with
report
andtitlesec
, the correct syntax of\titlespacing
isor
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 withouttitlesec
:You could redefine
\@makechapterhead
which typesets the chapter title. Here I took the default definition and commented everything you don't want.