4

I am numbering my index pages with roman numerals, but I'm writing the document using restructuredText that is parsed into LaTeX.

I have a preamble that contains all the necessary setup, but after the table of contents, it resets the page numbering back to 1, so \listoftables and \listoffigures show up at page (i) and (ii) respectively instead of (iii) and (iv) like they should. Since my table of contents could change, I don't want to use fixed page numbering.

There is a question that suggests rewriting \tableofcontents to storing the page number, but I have tried that and it didn't work. Since I am new here, I cannot comment on that one.

I would be willing to accept that I cannot fix this as long as I could disable page numbering for the TOC.

The following are the used classes and packages from the generated output:

% Generated by Sphinx.
\def\sphinxdocclass{report}
\documentclass[letterpaper,10pt, openany, oneside, english]{sphinxmanual}
\usepackage[utf8]{inputenc}
\DeclareUnicodeCharacter{00A0}{\nobreakspace}
\usepackage{cmap}
\usepackage[T1]{fontenc}
\usepackage{babel}
\usepackage{times}
\usepackage[Sonny]{fncychap}
\usepackage{longtable}
\usepackage{sphinx}
\usepackage{multirow}
% Include packages
\usepackage{lastpage}
\usepackage[table]{xcolor}
\usepackage{csvsimple}
\usepackage[hypcap]{caption}
\usepackage{booktabs}
\usepackage{wrapfig}
\usepackage{hyperref}
\usepackage[nottoc]{tocbibind}
\hypersetup{colorlinks,%
    citecolor=black,%
    filecolor=black,%
    linkcolor=black,%
    urlcolor=blue,%
pdftex}
\definecolor{lightgray}{gray}{0.9}
\let\oldtabular\tabular
\let\endoldtabular\endtabular

Since I have no control over when the table of contents will be called on, I also redefined the table of contents like this:

% Redefine table of contents to include the tables and figures
\newcounter{mypageno}
\let\oldtableofcontents\tableofcontents
\renewcommand{\tableofcontents}{%
  \oldtableofcontents%
  \cleardoublepage%
  \setcounter{mypageno}{\value{page}}%
  \pagenumbering{roman}%
  \setcounter{page}{\value{mypageno}}%
  \listoftables%
  \listoffigures%
  \cleardoublepage%
  \pagenumbering{arabic}%
}
2
  • 4
    \pagenumbering{..} resets the page counter to 1, so don't use it if you don't want it reset. Instead just change the numbering representation using something like \renewcommand{\thepage}{\roman{page}}.
    – Werner
    Feb 28, 2014 at 22:59
  • @Werner: I tried your suggestion, but no matter what I do, the page counter is reset after the table of contents so that the \listoftables starts on (i) again. Does one of the packages above redefine the \tableofcontents in such a way to force a \pagenumbering{arabic} after the TOC?
    – Jeremy
    Mar 3, 2014 at 16:18

1 Answer 1

2

First of all, \pagenumbering resets the page counter to 1, so don't use it if you don't want it reset. Instead just change the numbering representation using something like

\renewcommand{\thepage}{\roman{page}}

Now, I notice you're using the sphinxmanual document class. Looking at the code, we see a redefinition of \tableofcontents that includes a \pagenumbering:

% This wraps the \tableofcontents macro with all the magic to get the spacing
% right and have the right number of pages if the 'openright' option has been
% used.  This eliminates a fair amount of crud in the individual document files.
%
\let\py@OldTableofcontents=\tableofcontents
\renewcommand{\tableofcontents}{%
  \setcounter{page}{1}%
  \pagebreak%
  \pagestyle{plain}%
  {%
    \parskip = 0mm%
    \py@OldTableofcontents%
    \if@openright%
      \ifodd\value{page}%
        \typeout{Adding blank page after the table of contents.}%
        \pagebreak\hspace{0pt}%
      \fi%
    \fi%
    \cleardoublepage%
  }%
  \pagenumbering{arabic}% <--------------- This resets the page to 1
  \@ifundefined{fancyhf}{}{\pagestyle{normal}}%
}

You can remove this reset of the page number by adding the following to your preamble before you redefine \tableofcontents:

\usepackage{etoolbox}% http://ctan.org/pkg/etoolbox
% \patchcmd{<cmd>}{<search>}{<replace>}{<success>}{<failure>}
\patchcmd{\tableofcontents}{\pagenumbering{arabic}}{}{}{}

Note that the page style may also be adjusted by sphinxmanual's definition of \tableofcontents. But for now this should get where you want.

9
  • Thanks! That was it! The patching of the \tableofcontents solved it. I already had \makeatletter in my preamble so I didn't need to add that.
    – Jeremy
    Mar 3, 2014 at 21:43
  • @DaFlame: Sure thing. By the way, the \makeatletter...\makeatother pair was actually not necessary in my patch, but it would matter in your case.
    – Werner
    Mar 3, 2014 at 21:44
  • Hmmm... Now I seem to have another problem. The table of contents is not listing the List of Tables and List of Figures at the correct page number. It lists them as (ii) and (iii) instead of (iii) and (iv) like they should be.
    – Jeremy
    Mar 3, 2014 at 21:47
  • @DaFlame: Note that your document class is called with the openany option, implying that \cleardoublepage is just the same as \clearpage. If you wish to always start a chapter on an odd page, then you should use the openright class option. See How to start new chapters on the right hand side.
    – Werner
    Mar 3, 2014 at 21:51
  • I'm not interested in formal book style really. This is more like a report that will be viewed digitally. If printed, it would be presented in a stapled single page form not via book binding. I'm only interested in correcting the page numbering right now. I suppose I can forgo adding the Tables and Figures to the TOC, but I like having them there.
    – Jeremy
    Mar 4, 2014 at 17:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .