![如何中断页码编号并自动从最后一页重新开始?](https://linux22.com/image/475223/%E5%A6%82%E4%BD%95%E4%B8%AD%E6%96%AD%E9%A1%B5%E7%A0%81%E7%BC%96%E5%8F%B7%E5%B9%B6%E8%87%AA%E5%8A%A8%E4%BB%8E%E6%9C%80%E5%90%8E%E4%B8%80%E9%A1%B5%E9%87%8D%E6%96%B0%E5%BC%80%E5%A7%8B%EF%BC%9F.png)
当我撰写文档时,我通常会将其分成多个部分:因此,我通常不对部分页面进行编号,就像下面的示例一样,我将文档分为三个部分,例如序曲、第一部分和第二部分。因此,正如您所看到的,我使用设置计数器恢复页码,其中我手动指示了最后一个编号页面的最后一个值;但是,在撰写过程中,我经常需要在任意部分添加内容,以便有更多时间手动更新设置计数器页面值:可以自动执行此操作吗?有人可以帮我吗?
\documentclass{report}
\usepackage{hyperref}
\setcounter{chapter}{-1}
\begin{document}
\pagenumbering{gobble}
\tableofcontents
\chapter*{Preface}
\addcontentsline{toc}{chapter}{Preface}
\pagenumbering{arabic}
\newpage
\pagenumbering{gobble}
\quad
\part*{Overture}
\addcontentsline{toc}{part}{Overture}
\newpage
\pagenumbering{gobble}
\quad
\chapter*{Introduction}
\addcontentsline{toc}{chapter}{Introduction}
\pagenumbering{arabic}
\setcounter{page}{2}
\chapter{Chapter 0}
\newpage
\pagenumbering{gobble}
\quad
\part*{Part I}
\addcontentsline{toc}{part}{Part I}
\newpage
\pagenumbering{gobble}
\quad
\chapter{Chapter 1}
\pagenumbering{arabic}
\setcounter{page}{4}
\chapter{Chapter 2}
\chapter{Chapter 3}
\newpage
\pagenumbering{gobble}
\quad
\part*{Part II}
\addcontentsline{toc}{part}{Part II}
\newpage
\pagenumbering{gobble}
\quad
\chapter{Chapter 4}
\pagenumbering{arabic}
\setcounter{page}{7}
\chapter{Chapter 5}
\chapter{Chapter 6}
\end{document}
答案1
我不会这么做。每页都应该有一个编号(也许不会打印)。
无论如何,你可以这样做。主要问题是避免重复的锚点(你总是永远\pagenumbering{gobble}
不要使用)。
\documentclass{report}
\usepackage{xpatch}
\usepackage{hyperref}
\newcounter{savepage}
\newcounter{savenopage}
\newcommand{\nonumbering}[1]{%
\clearpage
\addtocontents{toc}{\protect\tocpagenumberfalse}%
\setcounter{savepage}{\value{page}}%
\pagenumbering{Alph}%
\pagestyle{empty}%
\setcounter{page}{\value{savenopage}}%
#1%
\clearpage
\addtocontents{toc}{\protect\tocpagenumbertrue}%
\pagestyle{plain}%
\setcounter{savenopage}{\value{page}}%
\pagenumbering{arabic}%
\setcounter{page}{\value{savepage}}%
}
\newif\iftocpagenumber
\tocpagenumbertrue
\makeatletter
\xpatchcmd{\part}{plain}{empty}{}{}
\xpatchcmd{\l@part}{#2}{\iftocpagenumber#2\fi}{}{}
\makeatother
\newcommand{\nopart}[1]{\part*{#1}\addcontentsline{toc}{part}{#1}}
\setcounter{chapter}{-1}
\begin{document}
\nonumbering{\tableofcontents}
\chapter*{Preface}
\addcontentsline{toc}{chapter}{Preface}
\nonumbering{\nopart{Overture}}
\chapter*{Introduction}
\addcontentsline{toc}{chapter}{Introduction}
\chapter{Chapter 0}
\nonumbering{\nopart{Part I}}
\chapter{Chapter 1}
\chapter{Chapter 2}
\chapter{Chapter 3}
\nonumbering{\nopart{Part II}}
\chapter{Chapter 4}
\chapter{Chapter 5}
\chapter{Chapter 6}
\end{document}
答案2
我会使用这样的东西:
\documentclass[chapterprefix,sfdefaults=false]{scrreprt}
\usepackage{hyperref}
\setcounter{chapter}{-1}% Chapter 0 is ugly style.
\renewcommand{\partpagestyle}{empty}% change page style of part
\begin{document}
\tableofcontents
\addchap{Preface}
\addpart{Overture}
\addchap{Introduction}
\chapter{Chapter 0}
\addpart{Part I}
\chapter{Chapter 1}
%\setcounter{page}{4}% would not do this
\chapter{Chapter 2}
\chapter{Chapter 3}
\addpart{Part II}
\chapter{Chapter 4}
%\setcounter{page}{7}% would not do this
\chapter{Chapter 5}
\chapter{Chapter 6}
\end{document}
是的,虽然示例没有显示页码,但它计算了部分页数。这避免了具有相同标识符的目标问题以及目录中部分页码的问题。一致的页码有助于读者,也可以避免作者出现问题。
但是,如果您愿意,您可以摆弄页码:
\documentclass[chapterprefix,sfdefaults=false]{scrreprt}
\usepackage{hyperref}
\setcounter{chapter}{-1}% Chapter 0 is ugly style.
\renewcommand{\partpagestyle}{empty}% change page style of part
\providecommand\gobble[1]{}
\DeclareTOCStyleEntry[pagenumberformat=\gobble]{tocline}{part}% don't show page numbers for part entries in ToC
\renewcommand*{\partheademptypage}{\addtocounter{page}{-1}\clearpage}% don't count part page; would not do this
\begin{document}
\tableofcontents
\addchap{Preface}
\addpart{Overture}
\addchap{Introduction}
\chapter{Chapter 0}
\addpart{Part I}
\chapter{Chapter 1}
\chapter{Chapter 2}
\chapter{Chapter 3}
\addpart{Part II}
\chapter{Chapter 4}
\chapter{Chapter 5}
\chapter{Chapter 6}
\end{document}
答案3
另一个可能的解决方案。
\documentclass{report}
\usepackage{hyperref}
\setcounter{chapter}{-1}
\makeatletter
\newcounter{savedpagevalue} %This line defines a new counter named savedpagevalue. Counters in LaTeX are variables used for numbering, such as page numbers, chapter numbers, etc.
%This command defines a new command named pagevalue. When called, it saves the current page number plus one in the counter savedpagevalue.
\newcommand{\pagevalue}{
\setcounter{savedpagevalue}{\value{page}}
\stepcounter{savedpagevalue}
}
\makeatother
%This command defines a new command named stoppagenumbering. When called, it stops the page numbering by printing no page numbers. It also increments the savedpagevalue counter and starts a new page
\newcommand{\stoppagenumbering}{
\pagevalue
\newpage
\pagenumbering{gobble}
}
%This command defines a new command named restartpagenumbering with one argument. When called with an argument specifying a page numbering style (such as arabic, Roman, etc.), it restarts the page numbering according to that style and sets the page number to the value stored in savedpagevalue.
\newcommand{\restartpagenumbering}[1]{
\clearpage
\pagenumbering{#1}
\setcounter{page}{\value{savedpagevalue}}
}
%This command defines a new command named blankpage. When called, it starts a new page, prints nothing on it (using \null), and suppresses any page numbering (using \thispagestyle{empty}).
\newcommand{\blankpage}{
\newpage
\null
\thispagestyle{empty}
}
\begin{document}
\pagenumbering{gobble}
\tableofcontents
\chapter*{Preface}
\pagenumbering{roman}
\addcontentsline{toc}{chapter}{Preface}
\stoppagenumbering
\blankpage
\part*{Overture}
\addcontentsline{toc}{part}{Overture}
\blankpage
\chapter*{Introduction}
\addcontentsline{toc}{chapter}{Introduction}
\pagenumbering{arabic}
\chapter{Chapter 0}
\stoppagenumbering
\blankpage
\part*{Part I}
\addcontentsline{toc}{part}{Part I}
\blankpage
\restartpagenumbering{arabic}
\chapter{Chapter 1}
\chapter{Chapter 2}
\chapter{Chapter 3}
\stoppagenumbering
\blankpage
\part*{Part II}
\addcontentsline{toc}{part}{Part II}
\blankpage
\restartpagenumbering{arabic}
\chapter{Chapter 4}
\chapter{Chapter 5}
\chapter{Chapter 6}
\end{document}