将 PDF 添加为新章节时,`\titleformat{\chapter}` 似乎不会触发

将 PDF 添加为新章节时,`\titleformat{\chapter}` 似乎不会触发

\includepdf我有一个工作流程,涉及通过包中的命令在报告中添加某些章节pdfpages。在此过程中,我希望某些 PDF 成为新章节的开始。并且每个章节之前都会有一个新页面,标题是我使用配置的\titleformat{\chapter}[display]。我使用addtotoc开关告诉 latex 将 PDF 添加为新章节并将其添加到目录中。在过去,这很有效,但在我的最新文档中,我发现在 PDF 章节之前没有出现带有章节标题的新页面。目录已更新,但没有章节标题页。我已将我的 tex 文件缩减为下面非常最小的可重现文档。该文件example.pdf是一个非常简单的 PDF 文档,用于测试。您可以点击下载

最让我困惑的是,我有另一个使用相同逻辑的工作流程……而且它有效。我无法找出下面的示例与正常运行的示例之间的实质性差异。

任何想法?

\documentclass{book}
\usepackage{pdfpages}        % for inserting pdfs
\usepackage{fancyhdr}        % for fancy editing of footers
\usepackage{titlesec}

\usepackage{lipsum}

\pdfminorversion=6     %kills PDF version warning in output
\pagestyle{fancy}

%% this sets up the title page for each chapter
\titleformat{\chapter}[display]
{\normalfont\Large\filcenter\sffamily}
{\titlerule[1pt] \vspace{1pt} \titlerule \vspace{1pc}
\LARGE\MakeUppercase{\chaptertitlename} \thechapter}
{1pc}
{\titlerule
\vspace{1pc}%
\Huge}
[\newpage] % creates the new page

\begin{document}

\tableofcontents

\includepdf[ pages=-, addtotoc={1,chapter,1,A. Ex 1,p1}]{./example.pdf}
\chapter{ch 2}
\lipsum{1-5}
\includepdf[ pages=-, addtotoc={1,chapter,1,A. Ex 3,p1}]{./example.pdf}

\end{document}

答案1

顾名思义addtotoc,此选项只是向目录添加条目,但实际上并不开始章节。如果您想要真正的章节(包括标题页),您只需在章节开始后添加 pdf 即可。

\documentclass{book}
\usepackage{pdfpages}        % for inserting pdfs
\usepackage{fancyhdr}        % for fancy editing of footers
\usepackage{titlesec}

\usepackage{lipsum}

\pdfminorversion=6     %kills PDF version warning in output
\pagestyle{fancy}

%% this sets up the title page for each chapter
\titleformat{\chapter}[display]
{\normalfont\Large\filcenter\sffamily}
{\titlerule[1pt] \vspace{1pt} \titlerule \vspace{1pc}
\LARGE\MakeUppercase{\chaptertitlename} \thechapter}
{1pc}
{\titlerule
\vspace{1pc}%
\Huge}
[\newpage] % creates the new page

\begin{document}

\tableofcontents

\chapter{A. Ex 1}
\includepdf[ pages=-,
% addtotoc={1,chapter,1,A. Ex 1,p1}
 ]{example-image-a4}
\chapter{ch 2}
\lipsum{1-5}
\chapter{A. Ex 3}
\includepdf[ pages=-,
% addtotoc={1,chapter,1,A. Ex 3,p1}
 ]{example-image-a4}

\end{document}

相关内容