小说模板中的问题

小说模板中的问题

我对以下代码有问题,该代码取自此网站背面。我将其添加\section{Section 1.1}到第 154 行,但问题是:在输出中,例如在 mainmatter 第 2 页的顶部,显示的是 01.1 而不是第 1.1 节。为什么?是否可以更改章节号,例如从第 01 章更改为第 1 章?

太感谢了

% universal settings
\documentclass[smalldemyvopaper,11pt,twoside,onecolumn,openright,extrafontsizes]{memoir}
\usepackage[utf8x]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[osf]{Alegreya,AlegreyaSans}

% PACKAGE DEFINITION
% typographical packages
\usepackage{microtype} % for micro-typographical adjustments
\usepackage{setspace} % for line spacing
\usepackage{lettrine} % for drop caps and awesome chapter beginnings
\usepackage{titlesec} % for manipulation of chapter titles

% for placeholder text
\usepackage{lipsum} % to generate Lorem Ipsum

% other
\usepackage{calc}
\usepackage{hologo}
\usepackage[hidelinks]{hyperref}
%\usepackage{showframe}

% PHYSICAL DOCUMENT SETUP
% media settings
\setstocksize{8.5in}{5.675in}
\settrimmedsize{8.5in}{5.5in}{*}
\setbinding{0.175in}
\setlrmarginsandblock{0.611in}{1.222in}{*}
\setulmarginsandblock{0.722in}{1.545in}{*}

% defining the title and the author
%\title{\LaTeX{} ePub Template}
%\title{\textsc{How I Started to Love {\fontfamily{cmr}\selectfont\LaTeX{}}}}
\title{My Two-line-long Title}
\author{The Author}
\newcommand{\ISBN}{0-000-00000-2}
\newcommand{\press}{My very own studio}

% custom second title page
\makeatletter
\newcommand*\halftitlepage{\begingroup % Misericords, T&H p 153
  \setlength\drop{0.1\textheight}
  \begin{center}
  \vspace*{\drop}
  \rule{\textwidth}{0in}\par
  {\Large\textsc\thetitle\par}
  \rule{\textwidth}{0in}\par
  \vfill
  \end{center}
\endgroup}
\makeatother

% custom title page
\thispagestyle{empty}
\makeatletter
\newlength\drop
\newcommand*\titleM{\begingroup % Misericords, T&H p 153
  \setlength\drop{0.15\textheight}
  \begin{center}
  \vspace*{\drop}
  \rule{\textwidth}{0in}\par
  {\HUGE\textsc\thetitle\par}
  \rule{\textwidth}{0in}\par
  {\Large\textit\theauthor\par}
  \vfill
  {\Large\scshape\press}
  \end{center}
\endgroup}
\makeatother

% chapter title manipulation
% padding with zero
\renewcommand*\thechapter{\ifnum\value{chapter}<10 0\fi\arabic{chapter}}
% chapter title display
\titleformat
{\chapter}
[display]
{\normalfont\scshape\huge}
{\HUGE\thechapter\centering}
{0pt}
{\vspace{18pt}\centering}[\vspace{42pt}]

% typographical settings for the body text
\setlength{\parskip}{0em}
\linespread{1.09}

% HEADER AND FOOTER MANIPULATION
  % for normal pages
  \nouppercaseheads
  \headsep = 0.16in
  \makepagestyle{mystyle} 
  \setlength{\headwidth}{\dimexpr\textwidth+\marginparsep+\marginparwidth\relax}
  \makerunningwidth{mystyle}{\headwidth}
  \makeevenhead{mystyle}{}{\textsf{\scriptsize\scshape\thetitle}}{}
  \makeoddhead{mystyle}{}{\textsf{\scriptsize\scshape\leftmark}}{}
  \makeevenfoot{mystyle}{}{\textsf{\scriptsize\thepage}}{}
  \makeoddfoot{mystyle}{}{\textsf{\scriptsize\thepage}}{}
  \makeatletter
  \makepsmarks{mystyle}{%
  \createmark{chapter}{left}{nonumber}{\@chapapp\ }{.\ }}
  \makeatother
  % for pages where chapters begin
  \makepagestyle{plain}
  \makerunningwidth{plain}{\headwidth}
  \makeevenfoot{plain}{}{}{}
  \makeoddfoot{plain}{}{}{}
  \pagestyle{mystyle}
% END HEADER AND FOOTER MANIPULATION

% table of contents customisation
\renewcommand\contentsname{\normalfont\scshape Contents}
\renewcommand\cftchapterfont{\normalfont}
\renewcommand{\cftchapterpagefont}{\normalfont}
\renewcommand{\printtoctitle}{\centering\Huge}

% layout check and fix
\checkandfixthelayout
\fixpdflayout

% BEGIN THE DOCUMENT
\begin{document}
\pagestyle{empty}
% the half title page
\halftitlepage
\cleardoublepage
% the title page
\titleM
\clearpage
% copyright page
\noindent{\small{This novel is entirely a work of fiction. The names, characters and incidents portrayed in it are the product of the author's imagination. Any resemblance to actual persons, living or dead, or events or localities is entirely coincidental.\par\vfill\noindent Paperback Edition\space\today\\ISBN\space\ISBN\\\copyright\space\theauthor. All rights reserved.\par\vfill\noindent\theauthor\space asserts the moral right to be identified as the author of this work. All rights reserved in all media. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form, or by any means, electronic, mechanical, photocopying, recording or otherwise, without the prior written permission of the author and/or the publisher.\par}}
\clearpage

% dedication
\begin{center}
\itshape{\noindent{Dedicated to my all {\fontfamily{cmr}\selectfont\LaTeX{}} users.}}
\end{center}

% begin front matter
\frontmatter
\pagestyle{mystyle}
% preface
\chapter*{Preface}
\lipsum[100-104]
% acknowledgements
\chapter*{Acknowledgements}
\lipsum[1-9]
% table of contents
\clearpage
\tableofcontents*

% begin main matter
\mainmatter
\chapter{Chapter One}
\section{Section 1.1}
\lipsum[1-20]
\chapter{Chapter Two}
\lipsum[21-40]
\chapter{Chapter Three}
\lipsum[41-60]
\chapter{Chapter Four}
\lipsum[61-80]
\chapter{Chapter Five}
\lipsum[81-100]
\chapter{Chapter Six}
\lipsum[101-120]

% begin back matter

\end{document}
% END THE DOCUMENT

答案1

你得到了你想要的:

% chapter title manipulation
% padding with zero
\renewcommand*\thechapter{\ifnum\value{chapter}<10 0\fi\arabic{chapter}}

如果不想要,则删除该行。

答案2

另一个答案已经涵盖了零填充。

对于章节标题格式:在 LaTeX 中,您不应该(永远)手动将数字添加到标题或说明等任何内容中 - LaTeX 的整个理念是自动添加、更新、引用等。因此,而不是:

\section{Section 1.1}

你写

\section{Section}

此外,你不应该手动编写某个类别。相反,你应该给出有意义的名称,让 LaTeX 自动添加诸如“部分”或“图形”之类的内容。或者,如果你不想添加有意义的名称,那么你应该定义不带参数的命令。

因此,不要写

\section{Section}

你应该写类似的东西

\section{Introduction}
or
\section{The Dinner}
or
\section{Cheese-flavored chocolate}

然后渲染成

1.1 介绍
1.2 晚餐
1.3 奶酪味巧克力

或者如果你不想要标题,那么创建一个新的命令,如下所示

\secnotitle    % hypothetical non-existing command that you can define
some text      % to print "Section X"

some text
\secnotitle

(假设)渲染可能类似于

第 1.1 节
部分文本
部分文本
第 1.2 节

也许你正在寻找某种组合,例如

第 1.1 节:简介

您可以使用titlesec已加载模板的包来执行此操作。此外,您还可以更改页眉的格式。包含两项修改的相关代码片段:

% chapter title manipulation
% padding with zero
%\renewcommand*\thechapter{\ifnum\value{chapter}<10 0\fi\arabic{chapter}}
% chapter title display
\titleformat
{\chapter}
[display]
{\normalfont\scshape\huge}
{\HUGE\thechapter\centering}
{0pt}
{\vspace{18pt}\centering}[\vspace{42pt}]

%%%%%% SET SECTION TITLE FORMAT HERE %%%%%%
\titleformat{\section}{\normalfont\Large\bfseries}{}{0em}{Section \thesection: }
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% typographical settings for the body text
\setlength{\parskip}{0em}
\linespread{1.09}

% HEADER AND FOOTER MANIPULATION
  % for normal pages
  \nouppercaseheads
  \headsep = 0.16in
  \makepagestyle{mystyle} 
  \setlength{\headwidth}{\dimexpr\textwidth+\marginparsep+\marginparwidth\relax}
  \makerunningwidth{mystyle}{\headwidth}
%%%%%% FORMAT OF PAGE HEADER HERE %%%%%%
  \makeevenhead{mystyle}{}{\textsf{\scriptsize\scshape \ifnum\value{section}>0 Section \thetitle\else\thechapter\fi}}{}
  \makeoddhead{mystyle}{}{\textsf{\scriptsize\scshape\leftmark}}{}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  \makeevenfoot{mystyle}{}{\textsf{\scriptsize\thepage}}{}
  \makeoddfoot{mystyle}{}{\textsf{\scriptsize\thepage}}{}
  \makeatletter
  \makepsmarks{mystyle}{%
  \createmark{chapter}{left}{nonumber}{\@chapapp\ }{.\ }}
  \makeatother
  % for pages where chapters begin
  \makepagestyle{plain}
  \makerunningwidth{plain}{\headwidth}
  \makeevenfoot{plain}{}{}{}
  \makeoddfoot{plain}{}{}{}
  \pagestyle{mystyle}
% END HEADER AND FOOTER MANIPULATION

线路

\makeevenhead{mystyle}{}{\textsf{\scriptsize\scshape \ifnum\value{section}>0 Section \thetitle\else\thechapter\fi}}{}

意思是:如果当前有一个章节(即章节计数器\value{section}不为零),那么我们打印“Section sec.num”,否则我们只打印章节编号。

结果:

在此处输入图片描述

相关内容