1

I have some document which contains header line and I also specified that chapters can begin on same page

Minimalized example below:

% !TeX program = xelatex

\documentclass[10pt,a4paper,twoside]{report}
\usepackage{geometry}
\geometry{
        a4paper,
        total={170mm,250mm},    
        outer=15mm,
        inner=20mm,
        top=15mm,
    }

\setlength{\parindent}{0em}
\setlength{\parskip}{1em}

% to specify chapter titles
\usepackage{titlesec}
\titleformat{\chapter}[display]   
{\normalfont\huge\bfseries}{\chaptertitlename\ \thechapter}{5pt}{\LARGE}   
\titlespacing*{\chapter}{0pt}{0pt}{0pt}
\raggedbottom
\usepackage{lipsum}
\titleformat{\chapter}[display]
{\normalfont\bfseries}{}{0pt}{\Large}
\titleformat{\chapter}[hang]{\LARGE\bfseries}{\thechapter{. }}{0pt}{\LARGE\bfseries}

% to specify headers
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancypagestyle{plain}{\fancyhf{}\renewcommand{\headrulewidth}{1pt}
    \fancyhead[RE,LO]{}
    \fancyfoot[LE,RO]{}
    \fancyfoot[RE,LO]{\jobname}}


% to specify that chapters are on same page
\usepackage{etoolbox}
\makeatletter
\patchcmd\chapter
{\if@openright\cleardoublepage\else\clearpage\fi}
{\par}
{}{}
\makeatother

\begin{document}
    \chapter{INTRODUCTION}
Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text
    \chapter{FIRST CHAPTER}
    Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text
\end{document}

Using this code, I get this

enter image description here

However, I want to reduce the distance between header line and beginning of the chapter. This can be done by changing

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

to, for example,

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

However, if I do this, I get this:

enter image description here

As you can see, I get overlapping between end of one chapter and beggining of another one, which I do not want. In this specific example, I can get rid of this by inserting \vspace{0.5cm} (or any other desired number) before \chapter{FIRST CHAPTER}, but I want a more generic solution (I don't want to do this for each chapter alone, but for all chapters simultaneously).

What is the best way to achieve this?

2 Answers 2

1

With \titlespacing you are able adjust all the chapters at the same time.

Of course you have to choose good values for the before and the after separation.

For example \titlespacing*{\chapter}{0pt}{-3ex}{-3ex} works fine.

Using ex units will keep the proportions if you change the main text font size e.g. from 10pt to 12pt.

b

% !TeX program = xelatex

\documentclass[10pt,a4paper,twoside]{report}
\usepackage{geometry}
\geometry{
    a4paper,
    total={170mm,250mm},    
    outer=15mm,
    inner=20mm,
    top=15mm,
}
\usepackage{lipsum}

\setlength{\parindent}{0em}
\setlength{\parskip}{1em}

\usepackage{titlesec}

\titleformat{\chapter}[hang]{\LARGE\bfseries}{\thechapter{. }}{0pt}{\LARGE\bfseries}
\titlespacing*{\chapter}{0pt}{-3ex}{-3ex}% changed <<<<<<<<<<<<<<<<<<<<<<

\usepackage{fancyhdr}
\pagestyle{fancy}
\fancypagestyle{plain}{\fancyhf{}\renewcommand{\headrulewidth}{1pt}
    \fancyhead[RE,LO]{}
    \fancyfoot[LE,RO]{}
    \fancyfoot[RE,LO]{\jobname}}


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

\raggedbottom
\begin{document}
    \chapter{INTRODUCTION}
    Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text
    \chapter{FIRST CHAPTER}
    Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text
        \chapter{SECOND CHAPTER}
    Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text
    \chapter{THIRD CHAPTER}
    Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text
    \chapter{FOURTH CHAPTER}
    Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text
    Some text
\end{document}
0

After seeing this question Custom \chapter definition, I decided to redefine the chapter command as

\makeatletter
\let\stdchapter\chapter
\renewcommand*\chapter{%
    \@ifstar{\starchapter}{\@dblarg\nostarchapter}}
\newcommand*\starchapter[1]{\vspace{0.85cm}\stdchapter*{#1}}
\def\nostarchapter[#1]#2{\vspace{0.85cm}\stdchapter[{#1}]{#2}}
\makeatother

In other words, the new \chapter command contains both the \vspace and old \chapter command.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.