-2

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

Hector
  • 1
  • 3
    Welcome to TeX SX! This may depend on the document class you're using. Could you post a small, yet complete code illustrating your problem? – Bernard Apr 04 '21 at 12:38
  • Thank you! I see what you mean. Currently, I am using the report class but having switched it to the article class it seems to do what I want it to. However, it means I need to completely reformat my document. – Hector Apr 04 '21 at 12:50
  • 5
  • 1
    The article class doesn't have chapters. . For chapters, it is either the report or the book class. It is simple to obtain the formatting you want with the advanced interface – something like \titleformat{\chapter}{\LARGE\bfseries}[\chaptername~\thechapter}{1em}{}. – Bernard Apr 04 '21 at 12:59

2 Answers2

1

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).

z

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}

  1. \kant[1]

\section{A section} 2. \kant[2] \end{document}

Simon Dispa
  • 39,141
0

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}

enter image description here

Of course, you can replace \huge in the (re)definition above with e.g. \Huge etc., as desired.

chsk
  • 3,667