对于这样一个平庸的问题,我提前表示歉意。我在文档中使用 \addchap,并希望将其创建的章节标题居中。有人能帮我解决这个问题吗?
一位 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
欢呼吧,迈克
答案1
所有章节都以
如果所有章节都应居中,请使用
\renewcommand*\raggedchapter{\centering}
代码:
\documentclass{scrbook}
\renewcommand*\raggedchapter{\centering}
\usepackage{blindtext}% dummy text
\begin{document}
\tableofcontents
\addchap{Unnumbered chapter}
\blindtext
\chapter{Numbered chapter}
\blindtext
\end{document}
仅将未编号的章节居中
如果仅未编号的章节应居中并且没有chapterprefix
您可以重新定义\chapterlinesformat
。
\makeatletter
\renewcommand{\chapterlinesformat}[3]{%
\ifstr{#2}{}{\centering}{}%
\@hangfrom{#2}{#3}%
}
\makeatother
但使用选项chapterprefix
命令 时\chapterlineswithprefixformat
必须重新定义。
\renewcommand{\chapterlineswithprefixformat}[3]{%
\ifstr{#2}{}{\centering}{}%
#2#3%
}
代码:
\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}