缺少数字,定义编号章节时视为零

缺少数字,定义编号章节时视为零

我遇到了一个看似常见的错误,但我不知道如何修复它。我有以下文档,正在使用 xelatex 进行处理。

\documentclass[12pt,english,oldfontcommands,openright]{memoir}

% For setting line height of individual blocks of text
\DisemulatePackage{setspace}
\usepackage{setspace}

% Select Font
%\usepackage{charter}
% Use GNU FreeSerif Font
\usepackage{fontspec}

% Great font for title page and chapter headings, but not the rest
\newfontfamily\headingfont{Quicksand-Regular.ttf}[
    Path           = fonts/,
    BoldFont       = Quicksand-Bold.ttf,
    ItalicFont     = Quicksand-Regular.ttf,
    BoldItalicFont = Quicksand-Bold.ttf
]

\usepackage{titlesec}
\titleformat{\chapter}[display]
  {\headingfont\centering}{\thechapter}{}{\Huge\textbf}

% Main text will be typeset in this font
\setmainfont{GaramondNo8-Reg.ttf}[
    Path           = fonts/,
    BoldFont       = GaramondNo8-Med.ttf,
    ItalicFont     = GaramondNo8-Ita.ttf,
    BoldItalicFont = GaramondNo8-MedIta.ttf
]

\renewcommand{\familydefault}{\rmdefault}

%showframe option VERY USEFUL for debugging!
\usepackage[xetex,paperwidth=7in,paperheight=10in,includehead,includefoot]{geometry}
% lmargin = inner, rmargin = outer
\geometry{verbose,tmargin=0.5in,bmargin=0.5in,lmargin=0.5in,rmargin=0.5in,headheight=18pt,headsep=0.25in,footskip=0.5in}

% In addition to paperwidth and paperheight in the geometry package setting,
% I need to set the stock size, a command defined by the memoir class, to actually
% change the physical page size to something custom.
\setstocksize{10in}{7in}

\setcounter{chapter}{0}
\setcounter{tocdepth}{0}
\usepackage{textcomp}
\usepackage{graphicx}
\usepackage{sidecap}

\makeatletter
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands.
\usepackage{microtype} % reduce amount of unnecessary and broken hyphenation
\usepackage{lettrine}
\renewcommand{\LettrineTextFont}{\rmfamily} % text following drop cap lowercase
\let\footruleskip\undefined % make memoir ignore fancyhead method
\usepackage{fancyhdr}

\fancypagestyle{fancyfacing}{
\fancyhead{} %clear head
\fancyfoot{} % clear foot
\fancyfoot[CO]{\headingfont\thepage}
\fancyfoot[CE]{\headingfont\thepage}
\fancyhead[CE]{\itshape Title}
\fancyhead[CO]{\itshape Athor}
\renewcommand{\headrulewidth}{0pt} %hide header rule
}

% Redefine the plain page style for chapters
\fancypagestyle{plain}{
\fancyhead{} %clear head
\fancyfoot{} % clear foot
\fancyfoot[CO]{\thepage}
\fancyfoot[CE]{\thepage}
\renewcommand{\headrulewidth}{0pt} %hide header rule
}

% \renewcommand*{\printchapternonum}{\centering} % alternative centre chapter
\renewcommand\chaptitlefont{\centering\normalfont\huge\bfseries\noindent} %center chapter titles
\setlength{\pfbreakskip}{\baselineskip} % make pfbreak one line space height
\setlength{\parskip}{0pt} %gap between paras same as line space
\setlength{\parsep}{0pt} %gap between paras same as line space

\makeatother

\usepackage{babel}

\begin{document}
\frontmatter
\pagestyle{empty}
\vspace*{\stretch{1}}

% Have an extra blank page at the beginning of the book.
\newpage{}
\vspace*{\stretch{1}}
\newpage{}

% Title page
\include{include/titlepage}

\newpage{}

% Copyright page
\include{include/copyright}

\newpage{}

% Insert extra blank page
\newpage{}
\vspace*{\stretch{1}}
\newpage{}

\clearpage{}
\mainmatter
\pagestyle{fancyfacing}

\chapter{Chapter name}

Some text for the chapter

\pagestyle{empty}

% Skip a page so that we start on the right again
\newpage{}
\vspace*{\stretch{1}}
\newpage{}

% Insert extra blank page (both sides)
\newpage{}
\vspace*{\stretch{1}}
\newpage{}

\end{document}

我收到以下错误:

! Missing number, treated as zero.
<to be read again> 
                   \relax 
l.1 \chapter{Chapter Name}

如果我使用 \chapter*{Chapter Name} 而不是 \chapter{Chapter Name},就不会出现该错误,但不幸的是我需要生成目录,所以我需要对章节进行编号。

如果能提供任何帮助来找出这个错误是从哪里来的,我将不胜感激!:)

答案1

问题在于缺少 的<sep>参数\titleformat。您不能将其留空。这就是缺少的数字。以下内容可以编译(但titlesec的文档仍然建议您不要将其与 一起使用memoir):

\documentclass[12pt,oldfontcommands,openright]{memoir}

\def\headingfont{\rmfamily}

\usepackage{titlesec}
\titleformat{\chapter}[display]
  {\headingfont\centering}{\thechapter}{0pt}{\Huge\textbf}

\renewcommand{\familydefault}{\rmdefault}

\setstocksize{10in}{7in}

\setcounter{tocdepth}{0}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands.
%\renewcommand\chaptitlefont{\centering\normalfont\huge\bfseries\noindent} % this line appears to have no effect with `titlesec`

\begin{document}
\chapter{Chapter name}

Some text for the chapter
\end{document}

相关内容