At the moment my headings are as follows:
Chapter 1
Title of chapter
Is there anyway to reformat the headings so that they are all on one line? i.e.
Chapter 1: Title of chapter
At the moment my headings are as follows:
Chapter 1
Title of chapter
Is there anyway to reformat the headings so that they are all on one line? i.e.
Chapter 1: Title of chapter
You want to customize the chapter titles. There are several ways to do it.
But with foresight you will also want to harmonize section titles, subsection, etc.
There are several parameters to take into account: the font and style of the chapter/section name and the chapter/section title, their relative positions, etc. and also the vertical spaces before and after. The same with subsection, part, ...
With the titlesec package you get a nice interface to play with these parameters, using the familiar LaTeX commands, until you get the result you like best.
There are two commands \titleformat and \titlepacing to use for quick setup (manual section #2 only).
This is the code used.
\documentclass[a4paper,12pt]{book}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{kantlipsum} % dummy text
\usepackage{titlesec} % added <<<<<<
%%%%%%%%%% chapters
\titleformat
{\chapter} % command to format
[block] % shape: hang, display, block, frame etc
{\sffamily\bfseries\Large} % format of label + chapter title
{\chaptertitlename\ \thechapter:} % label "Chapter 1:"
{1.5ex} % separation label - chapter title
{} % code before
\titlespacing{\chapter}
{0pt} %left of the label + title
{0} % vertical space before the title
{6.5} % idem after title (in ex units + glue)
%%%%%%%%%%%%%% sections
\titleformat{\section}
[block] % shape
{\sffamily\bfseries\itshape}% format (keep the chapter font family!)
{\thesection.} % label "1.1."
{0.8ex}% separation label - section title
{}
\titlespacing{\section}
{0pt} %left of label + section title
{4} % before the label + section title
{1.5} % after
\begin{document}
\chapter{The First}
- \kant[1]
\section{A section}
2. \kant[2]
\end{document}
Looking at the book class, for example, it seems that \chapter calls \@chapter which in turns calls \@makechapterhead, with the following definition:
\@makechapterhead:
macro:#1->\vspace *{50\p@ }{\parindent \z@ \raggedright \normalfont \ifnum \c@secnumdepth >\m@ne \if@mainmatter \huge \bfseries \@chapapp \space \thechapter \par \nobreak \vskip 20\p@ \fi \fi \interlinepenalty \@M \Huge \bfseries #1\par \nobreak \vskip 40\p@ }
Redefining this to remove the paragraph break etc. between \thechapter and the chapter title, #1, appears to work:
\documentclass{book}
\makeatletter
\renewcommand{\@makechapterhead}[1]{
\vspace *{50\p@ }{\parindent \z@ \raggedright \normalfont %
\ifnum \c@secnumdepth >\m@ne \if@mainmatter \huge \bfseries %
\@chapapp \space \thechapter: \bfseries #1\par \nobreak \vskip 40\p@ }%
}
\makeatother
\begin{document}
\chapter{Test}
\end{document}
Of course, you can replace \huge in the (re)definition above with e.g. \Huge etc., as desired.
\titleformat{\chapter}{\LARGE\bfseries}[\chaptername~\thechapter}{1em}{}. – Bernard Apr 04 '21 at 12:59