13

In the MWE below. What is the most convenient way to center the titles Preface and Abstract, rather than setting them flush left?

\documentclass{book}
\begin{document}

\chapter*{Preface}
\chapter*{Abstract}

\chapter{Introduction}
\chapter{Body}
\chapter{Conclusion}

\end{document}
PieterKJ
  • 1,055

5 Answers5

18

Since this about the \chapter* command for two titles (Abstract and Preface) only, it's sufficient to say \chapter*{\centering Abstract} etc. as command. This is grouped inside the internal command \@makeschapterhead -- it does not have a side effect on other implicitly used \chapter* commands, such as in \tableofcontents.

(The \blindtext as well as Some text aren't centered, so the \centering inside the \chapter* argument is safe, as long as no entry to the ToC is necessary (which is not the case, as we are talking about \chapter*)

If all \chapter* or \chapter titles should be centered horizontally, an \xpatchcmd approach is more useful. (See the edit at the bottom of this answer)

\documentclass{book}



\usepackage{blindtext}

\begin{document}

\chapter*{\centering Preface}
\blindtext

Some text
\chapter*{\centering Abstract}


\chapter{Introduction}
\chapter{Body}
\chapter{Conclusion}

\end{document}

enter image description here

Edit

This code centers all chapter titles (regardless whether \chapter* or \chapter) horizontally

\documentclass{book}

\usepackage{xpatch}
\usepackage{blindtext}


\makeatletter

\xpatchcmd{\@makeschapterhead}{%
  \Huge \bfseries  #1\par\nobreak%
}{%
  \Huge \bfseries\centering #1\par\nobreak%
}{\typeout{Patched makeschapterhead}}{\typeout{patching of @makeschapterhead failed}}


\xpatchcmd{\@makechapterhead}{%
  \huge\bfseries \@chapapp\space \thechapter
}{%
  \huge\bfseries\centering \@chapapp\space \thechapter
}{\typeout{Patched @makechapterhead}}{\typeout{Patching of @makechapterhead failed}}

\makeatother

\begin{document}
\tableofcontents

\chapter*{Preface}
\blindtext

Some text
\chapter*{Abstract}
\blindtext


\chapter{Introduction}
\blindtext

Another text


\chapter{Body}
\blindtext

\chapter{Conclusion}
\blindtext


\end{document}
1

I used \hfill before and after to do the trick, however, titlesec package is also required

\phantomsection
\chapter*{\hfill{\centering Certificate}\hfill}

Full working example

\documentclass{book}
\usepackage[showframe]{geometry}%optional
%titlesec is also required with these commands
\usepackage{titlesec}
\titleformat{\chapter}[display]
{\normalfont\huge\bfseries}{\chaptertitlename\ \thechapter}{20pt}{\Huge}
\titlespacing*{\chapter} {0pt}{50pt}{40pt}
%
\begin{document}
\chapter*{\hfill{\centering Certificate}\hfill}
\end{document}
  • Did you test this? It doesn't centre the chapter heading; it's flush right. Also, it requires some work if you have headings that carry the \chapter* title, as well as writing stuff to the ToC. – Werner Mar 02 '21 at 20:48
  • I have tested it, it works for me that's why I have shared it. – Prateek Raj Gautam Mar 04 '21 at 05:50
  • I tried this example code and obtained a flush right chapter title. – Werner Mar 04 '21 at 06:44
  • Share the code so we can replicate your error then we might help. – Prateek Raj Gautam Mar 04 '21 at 19:50
  • Without hyperref: code; with hyperref: code – Werner Mar 04 '21 at 19:53
  • thanks for pointing, I have updated my previous answer, looks like it also requires titlesec package \documentclass{book} \usepackage[showframe]{geometry}%optional %titlesec is also required with these commands \usepackage{titlesec} \titleformat{\chapter}[display] {\normalfont\huge\bfseries}{\chaptertitlename\ \thechapter}{20pt}{\Huge} \titlespacing{\chapter} {0pt}{50pt}{40pt} % \begin{document} \chapter{\hfill{\centering Certificate}\hfill} \end{document} – Prateek Raj Gautam Mar 04 '21 at 20:45
1

Here is a solution that worked with me

\titleformat{\chapter}[display]
  {\normalfont\huge\bfseries\centering}{\centering\chaptertitlename\ \thechapter}{20pt}{\Huge}
\titlespacing*{\chapter} 
  {0pt}{50pt}{40pt}

from the link below

centering a chapter title

WinnieNotThePooh
  • 3,008
  • 1
  • 7
  • 14
0

adjust thesis title page centering:

https://www.youtube.com/watch?v=6NDqLSW9KEw

  • 3
    Please add a meaningful MWE. Don't just link to external pages containing the LaTeX code. External links can become invalid or inaccessible, and the answer could lose any value to future visitors. It's also much easier to use code typed out properly rather than in a youtube video – Willoughby Jul 06 '21 at 14:14
0

Below is a very simple approach to center all chapter titles by default, compared to the answer from user31729:

\usepackage{titlesec}
\titleformat{\chapter}[display]
  {\centering \normalsize \huge  \color{black}}{\thechapter}{10pt}{}

Now,

\chapter*{Curriculum Vitae}

produces

enter image description here

and

\chapter{Curriculum Vitae}

produces

enter image description here

zkytony
  • 133