如何將章節標題加入標題和目錄?

如何將章節標題加入標題和目錄?

我正在嘗試自訂一個最初為小說設計的模板。我已向其添加了部分,我希望在左頁上看到書名作為標題,在頁面的中心,在右頁和頁面的中心看到標題本章的內容。我特別想看到我的目錄中編號的所有小節。我怎麼能這麼做呢?

這是我的mwe:

\documentclass[smalldemyvopaper,10pt,twoside,onecolumn,openright,extrafontsizes]{memoir}
\usepackage[utf8]{inputenc}
\usepackage [frenchb]{babel}
\usepackage[T1]{fontenc}
\usepackage[osf]{Alegreya,AlegreyaSans}


\usepackage{lipsum}

% 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{A title}

\author{My name}
\newcommand{\ISBN}{0-000-00000-2}
\newcommand{\press}{Nom de l'éditeur}

% 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\LARGE}
{\huge\thechapter\centering}
{0pt}
{\vspace{18pt}\centering}[\vspace{22pt}]

% 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

% begin front matter
\frontmatter
\pagestyle{mystyle}

\chapter{Introduction}

\mainmatter
\part{A part}

\chapter{A chapter}

\section{A section}
\lipsum



\end{document}

答案1

  1. 首先,我強烈建議考慮@Zarko 的評論,因為您面臨的問題很大程度上是由於memoir類別和titlesec套件之間的一些不相容造成的。

  2. \thetitle類別定義的命令由套件memoir重新定義,titlesec因此我們需要之前儲存它的值。所以我們定義一個新的巨集edef\TheTitle{\thetitle}並用它來設定標題

    \makeevenhead{mystyle}{}{\textsf{\scriptsize\scshape\TheTitle}}{}
    \makeoddhead{mystyle}{}{\textsf{\scriptsize\scshape\leftmark}}{}
    
  3. 對 s 進行編號subsection並在目錄中查看它們:

%

 \maxsecnumdepth{subsection}
 \maxtocdepth{subsection}

完整程式碼

\documentclass[smalldemyvopaper, 10pt, twoside, onecolumn, openright, extrafontsizes]{memoir}
\usepackage[utf8]{inputenc}
\usepackage [frenchb]{babel}
\usepackage[T1]{fontenc}
\usepackage[osf]{Alegreya,AlegreyaSans}

\usepackage{lipsum}

% 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{The book title}

\author{My name}
\newcommand{\ISBN}{0-000-00000-2}
\newcommand{\press}{Nom de l'éditeur}

\edef\TheTitle{\thetitle}

% 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\LARGE}
{\huge\thechapter\centering}
{0pt}
{\vspace{18pt}\centering}[\vspace{22pt}]

% 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

% begin front matter
\frontmatter
\pagestyle{mystyle}

\maxtocdepth{subsection}
\maxsecnumdepth{subsection}

\tableofcontents

\chapter{Introduction}

\mainmatter
\part{A part}

\chapter{A chapter}

\section{A section}

\subsection{A subsection}

\lipsum

\end{document}

在此輸入影像描述

在此輸入影像描述

相關內容