第 1 页,共 ... 页,总页数过多

第 1 页,共 ... 页,总页数过多

我的文档有封面和目录。页码设置为显示Page 1 of ...。上下文忽略封面并将标题页设置为第 1 页,但在计算文档的总页数时会包含封面。这会导致最后一页显示问题Page n-1 of n

我该如何解决此问题?

顺便说一句,我感兴趣的是为什么我必须在封面上放置startstandardmakeupstopstandardmakeup显示图形。

MWE 如下:

% Turn off page numbering as it is set in the footer
\setuppagenumbering[location=]
% Setup headers and footers
\setupfootertexts[][Page \pagenumber{} of \totalnumberofpages]

% Set up Cover Page
\defineoverlay[CoverPage]
              [{\externalfigure[cow][cow]}]

\setupexternalfigures[location={local,global,default}]

%start document
\starttext

\setupbackgrounds[page][background={CoverPage,CoverTitle}]

\startstandardmakeup
\stopstandardmakeup

\setupbackgrounds[page][background=]

% Insert TOC
\setupcombinedlist[content][list={chapter,section,subsection},alternative=c]
\completecontent
\page[yes]

%start main part of document
\input ward 

\page[yes]

\startsection[title={Title 1}]
\input ward 
\page[yes]
\stopsection

\startsection[title={Title 2}]
\input ward 
\page[yes]
\stopsection

\startsection[title={Title 3}]
\input ward 
\page[yes]
\stopsection

\stoptext

答案1

您正在寻找的命令是:\currentpage\ of \lastpage

% Turn off page numbering as it is set in the footer
\setuppagenumbering[location=]
% Setup headers and footers
\setupfootertexts[][Page \currentpage\ of \lastpage]

% Set up Cover Page
\defineoverlay[CoverPage]
              [{\externalfigure[cow][cow]}]

\setupexternalfigures[location={local,global,default}]

%start document
\starttext

\setupbackgrounds[page][background={CoverPage,CoverTitle}]

\startstandardmakeup
\stopstandardmakeup

\setupbackgrounds[page][background=]

% Insert TOC
\setupcombinedlist[content][list={chapter,section,subsection},alternative=c]
\completecontent
\page[yes]

%start main part of document
\input ward

\page[yes]

\startsection[title={Title 1}]
\input ward
\page[yes]
\stopsection

\startsection[title={Title 2}]
\input ward
\page[yes]
\stopsection

\startsection[title={Title 3}]
\input ward
\page[yes]
\stopsection

\stoptext

关于您的补充:\startstandardmakeup\stopstandardmakeup插入一个新的空白页,没有页脚和页眉。这是必要的,因为您想将封面页作为背景图像。

答案2

我建议你使用userpage计数器,因为它会自动排除未计数的页面,例如封面。要以任何方式计算封面,只需将其添加pagestate=start到标准构成中即可。

此外,您还可以使用诸如\start...\stopfrontmatter和的结构\start...\stopbodymatter,而不必在任何地方手动插入分页符。要在新的部分之前自动分页,只需使用

\setuphead
  [section]
  [page=yes]

这使得代码更清晰,大多数注释现在都是多余的。

% Turn off page numbering as it is set in the footer
\setuppagenumbering[location=]
% Setup headers and footers
\setupfootertexts[][Page \userpagenumber\ of \lastuserpagenumber]

% Set up Cover Page
\defineoverlay[CoverPage]
              [{\externalfigure[cow]}]

\setupexternalfigures[location={local,global,default}]

\setuphead
  [section]
  [page=yes]

\starttext

\startfrontmatter

  \setupbackgrounds[page][background=CoverPage]
  \startstandardmakeup[pagestate=start]
  \stopstandardmakeup
  \setupbackgrounds[page][background=]

  \setupcombinedlist[content][list={chapter,section,subsection},alternative=c]
  \completecontent

\stopfrontmatter

\startbodymatter

  \input ward

  \startsection[title={Title 1}]
    \input ward 
  \stopsection

  \startsection[title={Title 2}]
    \input ward 
  \stopsection

  \startsection[title={Title 3}]
    \input ward 
  \stopsection

\stopbodymatter

\stoptext

相关内容