4

My apologies in advance for such a banal question. I am using \addchap in a document and, would like to centre the chapter heading it creates. Could someone help me out with this please?

A MWE:

  \documentclass[12pt,english,british,twoside,openany]{scrbook}
  \usepackage{fontspec}
  \setmainfont{Gill Sans}
  \usepackage{lettrine}
  \usepackage[automark,headsepline=.25pt]{scrlayer-scrpage}
  \usepackage{microtype}
  \usepackage{ragged2e}
  \usepackage{graphicx}
  \graphicspath{ {../img/} }
  \usepackage{wrapfig}
  \usepackage[british]{babel}
  \pagestyle{scrheadings}
  \addtokomafont{pageheadfoot}{\scshape}%changed to small caps in headers
  %\addtokomafont{pagehead}{\normalsize}
  \addtokomafont{pagehead}{\small}
  %\addtokomafont{pagefoot}{\normalsize}
  \addtokomafont{pagefoot}{\small}
  \addtokomafont{disposition}{\rmfamily} %for headings
  %\addtokomafont{disposition}
  \chead{Ben Francis}
  \ofoot{} %Author Name
  \ifoot{} % Chapter Number
  \lehead{\pagemark}
  \rohead{\pagemark}
  \cohead{\mytitle}
  \renewcommand\thepart{\Alph{part}}
  \linespread{1.05}
  \usepackage{hyphenat}
  \tolerance=1000
  \hyphenpenalty=1000
  \renewcommand*{\partpagestyle}{empty}
  \usepackage{geometry}
  \geometry{paperwidth=5.06in,paperheight=7.81in,
%   verbose,
%   tmargin=0.75in,
%   bmargin=0.75in,
%   inner=0.75in,
%   outer=0.5in,
%   headheight=0.1in,
%   headsep=0.15in,
%   footskip=0.45in,
    twoside}
  \newcommand{\mytitle}{Tears in the Rain} 
  \newcommand{\emptx}[1]{\textit{#1}}

%\RedeclareSectionCommand[
%indent=.25in,
%font=\fontsize{45}{40}\selectfont\mdseries\mathilde
%font=\fontsize{15}{10}
%]{section}

%\setkomafont{section}{\fontsize{15}{20}\selectfont\fontspec{Gill Sans}}
%\setkomafont{subsection}{\small}
%\setkomafont{subsubsection}{\small}
%\setkomafont{paragraph}{\normalsize}
%\setkomafont{subparagraph}{\normalsize}

\widowpenalty=300
\clubpenalty=300

 \setlength\parindent{8pt}

\begin{document}
    \title{\mytitle}
    \author{}
    \date{}
\frontmatter
\maketitle
\begin{titlepage}
    \begin{flushright}
        {\huge \mytitle}
        \par\end{flushright}{\huge \par}
\end{titlepage}

\begin{titlepage}
    \noindent\includegraphics[width=4in,height=1.5in]{./titrbensig}
    \vspace*{0.5in}
    \begin{flushright}
        \Huge{Tears in the Rain}
        \par\end{flushright}{\Huge \par}

    \clearpage
    \thispagestyle{empty}

    \begin{center}
        \emph{Copyright}
    \end{center}
    \begin{center}
        \textcopyright{ 2014 Ben Francis All rights reserved.}
    \end{center}
    \vspace*{0.5in}
    \begin{center}
        \begin{minipage}[t]{0.5\paperwidth}
            No part of this publication may be reproduced, stored in a retrieval system, or transmitted in any form, or by any means;
            mechanical, electrical, photocopying, scanning, recording or
            otherwise, without prior written consent from the publishers. Every
            effort has been made to contact all copyright holders. The author and
            publisher will gladly rectify any omissions.
        \end{minipage}
    \end{center}
    \vspace*{0.5in}
    \begin{center}
        ISBN:
    \end{center}
    \vspace*{0.2in}
    \begin{center}
        A CIP Record for this book is available from the British
        Library.
    \end{center}
    \vspace*{0.1in}
    \begin{center}
        Typeset in \LaTeXe
    \end{center}
\end{titlepage}

\pagenumbering{gobble}% Remove page numbers (and reset to 1)
\tableofcontents

\addchap{PREFACE}
\input{./titr_pref.tex}     
\mainmatter
\addchap{ONE}
\input{./titr01.tex}
\end document

Cheers, Mike

  • Can you give a MWE? – juanuni Apr 3 '16 at 18:25
  • Do you only want the chapter headings centered you added with \addchap? Or all the chapter headings? – Benjamin Apr 3 '16 at 18:39
  • Benjamin- Each chapter heading added by an instance of \addchap (I am using only \addchap). – Mike Apr 3 '16 at 18:47
  • Apologies - I have no idea how to add a MWE via an edit so, made a bit of a mess of this one. – Mike Apr 3 '16 at 18:48
4

All chapters centred

If all chapters should be centered use

\renewcommand*\raggedchapter{\centering}

enter image description here

Code:

\documentclass{scrbook}
\renewcommand*\raggedchapter{\centering}

\usepackage{blindtext}% dummy text
\begin{document}
\tableofcontents
\addchap{Unnumbered chapter}
\blindtext
\chapter{Numbered chapter}
\blindtext
\end{document}

Only unnumbered chapters centered

If only unnumbered chapters should be centered and there is no chapterprefix you can redefine \chapterlinesformat.

\makeatletter
\renewcommand{\chapterlinesformat}[3]{%
  \ifstr{#2}{}{\centering}{}%
  \@hangfrom{#2}{#3}%
}
\makeatother

But with option chapterprefix command \chapterlineswithprefixformat must be redefined.

\renewcommand{\chapterlineswithprefixformat}[3]{%
  \ifstr{#2}{}{\centering}{}%
  #2#3%
}

enter image description here

Code:

\documentclass
  %[chapterprefix]
  {scrbook}[2015/10/03]

\makeatletter
\renewcommand{\chapterlinesformat}[3]{%
  \ifstr{#2}{}{\centering}{}%
  \@hangfrom{#2}{#3}%
}
\makeatother
\renewcommand{\chapterlineswithprefixformat}[3]{%
  \ifstr{#2}{}{\centering}{}%
  #2#3%
}
\usepackage{blindtext}% dummy text
\begin{document}
\tableofcontents
\addchap{Unnumbered chapter}
\blindtext
\chapter{Numbered chapter}
\blindtext
\end{document}
| improve this answer | |
  • esdd: Thank you it works just great! I am an author new to Latex - so still learning and climbing the hill....Cheers – Mike Apr 3 '16 at 18:56

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.