Modifying the Page Numbers in the Table of Contents
you can suppress the automatically generated toc entry and replace it.
to suppress, add this command to your preamble:
\DeclareRobustCommand{\SkipTocEntry}[4]{}
if you are using hyperref, change the [4]
to [5]
-- this is the number of elements in the toc entry to be suppressed.
immediately before the line that generates the toc entry, insert the line
\addtocontents{toc}{\SkipTocEntry}
if applying it to a chapter, and you use \include
to insert your chapters, it must be in the same file as the \chapter
command; if you put it in the driver file, the timing will be off, and the chapter entry from the next chapter will be suppressed instead.
a replacement entry should be inserted immediately after the line that generated the toc entry, in order to ensure that the page number has been resolved correctly.
define a counter \newcounter{prevpage}
in the preamble. when setting up the replacement toc entry,
\setcounter{prevpage}{\value{page}}
\addtocounter{prevpage}{-1}
then use \addtocontents{toc}{xxx}
where xxx
is the line that was automatically generated (and suppressed) that you can copy from the .toc
file, except that you should replace the assigned page number by {\theprevpage}
. if you had to \protect
some commands in the text of the original heading, you should do the same in the replacement toc entry.
say this line appears in the toc (the example is from a test using amsbook
):
\contentsline {section}{\tocsection {}{5}{Section title}}{10}
the page number is {10}
. what you'd put in your file as a replacement is
\addtocontents{toc}{\protect\contentsline {section}{\protect\tocsection {}{5}{Section title}}{\theprevpage}}
observe that \contentsline
and \tocsection
do need to be \protect
ed.
(i took this example from a test using amsart.cls
, but the principle should be the same regardless of the document class. just copy what's in the .toc
file from your first run, and modify it appropriately.)
EDIT: the OP created an admirable macro, \transsection
to handle this. what follows is a self-contained example file demonstrating the use of his macro with the book
class.
\documentclass{book}
\usepackage{verbatim}
\DeclareRobustCommand{\SkipTocEntry}[4]{}
\newcounter{prevpage}
\newcommand{\transsection}[1]{%
\addtocontents{toc}{\SkipTocEntry}%
\section{#1}%
\setcounter{prevpage}{\value{page}}\addtocounter{prevpage}{-1}%
\addtocontents{toc}{%
\protect\contentsline {section}{%
\protect\numberline {\thesection}#1}{\theprevpage}}}
\begin{document}
\frontmatter
\tableofcontents
\mainmatter
\chapter{First}
\section{First section}
some text
\clearpage
\transsection{Test section}
We want this section to have a page number one less than the
real one. This is from question 55645 in TeX.SX, where the
author is setting an Arabic page on the page before the
English translation page, and wants the TOC to show that
page number.
\vspace{1\baselineskip}
\verbatiminput{\jobname.tex}
\end{document}
The following example shows a way to do this for section
.
To use the special section I define the command \specialsection
. It's important to use \makeatletter
for the table of contents.
\documentclass{scrbook}
\makeatletter
\renewcommand\@pnumwidth{3.55em}
\let\@dottedtoclineorig\@dottedtocline
\def\local@dottedtocline#1#2#3#4#5{%
\ifnum #1>\c@tocdepth \else
\vskip \z@ \@plus.2\p@
{\leftskip #2\relax \rightskip \@tocrmarg \parfillskip -\rightskip
\parindent #2\relax\@afterindenttrue
\interlinepenalty\@M
\leavevmode
\@tempdima #3\relax
\advance\leftskip \@tempdima \null\nobreak\hskip -\leftskip
{#4}\nobreak
\leaders\hbox{$\m@th
\mkern \@dotsep mu\hbox{.}\mkern \@dotsep
mu$}\hfill
\nobreak
\hb@xt@\@pnumwidth{\hfil\normalfont \normalcolor \the\numexpr#5-1\relax~(x-1)}%
\par}%
\fi}
\newcommand\specialsection[2][]{%
\addtocontents{toc}{\protect\let\protect\@dottedtocline\protect\local@dottedtocline}
\ifx\relax#1\relax
\section{#2}
\else
\section[#1]{#2}
\fi
\addtocontents{toc}{\protect\let\protect\@dottedtocline\protect\@dottedtoclineorig}
}
\makeatother
\begin{document}
\makeatletter
\tableofcontents
\makeatother
\chapter{foo}
\backmatter
\chapter{foo}
\section*{arabic}
text in arabix
\clearpage
\specialsection{english}
text in English
\end{document}
Result: