我的文档有封面和目录。页码设置为显示Page 1 of ...
。上下文忽略封面并将标题页设置为第 1 页,但在计算文档的总页数时会包含封面。这会导致最后一页显示问题Page n-1 of n
。
我该如何解决此问题?
顺便说一句,我感兴趣的是为什么我必须在封面上放置startstandardmakeup
并stopstandardmakeup
显示图形。
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