2

In the following source document using the memoir class, I define my own chapterstyle that, among other things, stacks the chapter name ("Chapter" or "Appendix") above its number.

But despite using \centering there, the chapter name does not get centered. What's wrong?

% mychapstyle.tex
\documentclass{memoir}

\usepackage{anyfontsize}
\usepackage{lipsum}

\makeatletter
\makechapterstyle{my}{%
\chapterstyle{plain}
\renewcommand{\chapnamefont}{\sffamily\bfseries}
\renewcommand{\chapnumfont}{\fontsize{58}{64}\selectfont\sffamily\bfseries}
\renewcommand{\chaptitlefont}{\Huge\sffamily\bfseries}
%
\settoheight{\midchapskip}{\chapnumfont 1}
\setlength{\midchapskip}{0pt}
\setlength{\afterchapskip}{48pt}
%
\renewcommand{\printchaptername}{%
\chapnamefont\centering\MakeUppercase{\@chapapp}\newline}
%
\renewcommand*{\printchapternum}{\centering \chapnumfont\thechapter%
}
%
\renewcommand{\afterchapternum}{%
\par\nobreak\vskip \midchapskip%
\centering\rule{0.825\textwidth}{\normalrulethickness}%
\newline}
\renewcommand{\printchaptertitle}[1]{\centering\chaptitlefont ##1}
}% end makechapterstyle
\makeatother

\renewcommand*{\cftappendixname}{Appendix\space}

\makeindex

\begin{document}

\chapterstyle{my}

\frontmatter
\tableofcontents*

\chapter*{Preface}
\lipsum[1]

\mainmatter

\chapter{The First Chapter}
\lipsum[2]\index{lipsum}\index{lipsum!ipsum lorem}

\appendix
\chapter{Short Appendix}
\renewcommand{\thechapter}{A}
\lipsum[3]

\backmatter
\printindex

\end{document}

Here's the first page of the first chapter:

Chapter name to be centered

1 Answer 1

2

The problem is \newline in

\renewcommand{\printchaptername}{%
\chapnamefont\centering\MakeUppercase{\@chapapp}\newline}

replace it with \\ or \par:

\renewcommand{\printchaptername}{%
\chapnamefont\centering\MakeUppercase{\@chapapp}\\}

and you will obtain desired result:

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .