2

I want to preface this question with this is a requirement for the document I am writing to be published and would normally not use this format.

I am trying to format the headers of a list (e.g. Table of Contents, List of Figures, Bibliography, etc) to change automatically based on whether it is the first, last, or in-between of that list. For example, it the table of contents is five pages long, the first page's header would read "Table of Contents", the second through fourth page's header would read "Table of Contents (Continued)", and the last page's header would read "Table of Contents (Concluded)".

I have used atbegshi to get the main header (e.g. "Table of Contents", "List of Figures", etc) over every page of that section by using this code in the style file:

\newcommand{\tocheader}{{%
  \bfseries% Font selection
  \hspace*{\fill} \MakeUppercase{\contentsname} % Title heading
  \hspace*{\fill}
  \par
  \hfill%
  \makebox[\@pnumwidth][r]{\underline{Page}}% Page heading
  \par\kern.5\baselineskip% After heading
  }}

however, I have not been able to find a way to change it based on the page in the section. At this point, I will take manually editing the respective files (e.g. *.toc, *.lof, *.lot) to have it read this way.

Thank you in advance for your help and time. I greatly appreciate it.

  • 2
    Can you create a minimal document that starts with \documentclass and ends with \end{document} that provides a template the community can work from? Something that provides multiple pages within the ToC so we can copy-and-paste-and-compile and hit the ground running? Helping us would really help you in the end. – Werner Nov 1 '18 at 18:36
  • Thank you for your reply. I am sorry for not including this. I will remember this before making another post. – John Nov 2 '18 at 15:10
2

You can use the zref-package for placing labels whereof absolute page-numbers can be obtained.

You can patch/modify the \listof../\tableof...-macros for

  • having placed a label when starting the corresponding list/tableof...-thingie.

  • having placed a label when at the end of the corresponding list/tableof...-thingie.

  • having page-headers that themselves place labels.

Then you can compare the absolute page-numbers coming from the labels placed by the headers to the absolute page-numbers that come from the labels placed at the start and at the end of the corresponding list/tableof...-thingie and depending on the comparison-result either place no additional phrase at all or place the phrase (Continued) or place the phrase (Concluded).

Using the article-class, this could look like this:

\documentclass{article}
\usepackage[abspage]{zref}
%\usepackage{hyperref}

\newcount\mytmpcnt

\makeatletter
\renewcommand\tableofcontents{%
  \global\mytmpcnt=0 %
  \section*{\contentsname
            \@mkboth{\MakeUppercase\contentsname\protect\listcontinue{contents}}%
                    {\MakeUppercase\contentsname\protect\listcontinue{contents}}%
           }%
  \zref@labelbyprops{contentsstart}{abspage}%
  \@starttoc{toc}%
  \zref@labelbyprops{contentsend}{abspage}%
}%
\renewcommand\listoffigures{%
  \global\mytmpcnt=0 %
  \section*{\listfigurename}%
  \@mkboth{\MakeUppercase\listfigurename\protect\listcontinue{figures}}%
          {\MakeUppercase\listfigurename\protect\listcontinue{figures}}%
  \zref@labelbyprops{figuresstart}{abspage}%
  \@starttoc{lof}%
  \zref@labelbyprops{figuresend}{abspage}%
}%
\renewcommand\listoftables{%
  \global\mytmpcnt=0 %
  \section*{\listtablename}%
  \@mkboth{\MakeUppercase\listtablename\protect\listcontinue{tables}}%
          {\MakeUppercase\listtablename\protect\listcontinue{tables}}%
  \zref@labelbyprops{tablesstart}{abspage}%
  \@starttoc{lot}%
  \zref@labelbyprops{tablesend}{abspage}%
}%
\newcommand\listcontinue[1]{%
  \global\advance\mytmpcnt by1\relax
  \zref@labelbyprops{#1\number\mytmpcnt}{abspage}%
  \ifnum\zref@extractdefault{#1start}{abspage}{0}=%
        \zref@extractdefault{#1end}{abspage}{0} \else
    \ifnum\zref@extractdefault{#1\number\mytmpcnt}{abspage}{0}=%
          \zref@extractdefault{#1end}{abspage}{0} \MakeUppercase{\space(Concluded)}%
    \else
      \ifnum\zref@extractdefault{#1\number\mytmpcnt}{abspage}{0}=%
            \zref@extractdefault{#1start}{abspage}{0} \else
        \MakeUppercase{\space(Continued)}%
      \fi
    \fi
  \fi
}%
\makeatother


\pagestyle{headings}
\begin{document}

\tableofcontents
\newpage
\listoffigures
\newpage
\listoftables
\newpage

% In a loop create 99 sections, 99 figures and 99 tables.

\newcount\mytmpcntB
\mytmpcntB=0 %
\loop
\ifnum\mytmpcntB<99\relax
  \advance\mytmpcntB by 1\relax
  \section{Section \number\mytmpcntB}
  \begin{figure}[t]\hrulefill\caption{Figure \number\mytmpcntB}\hrulefill\end{figure}
  \begin{table}[t]\hrulefill\caption{Table \number\mytmpcntB}\hrulefill\end{table}
  Text of section \number\mytmpcntB.
  \newpage
\repeat

\end{document}

enter image description here enter image description here enter image description here enter image description here enter image description here enter image description here enter image description here enter image description here enter image description here enter image description here enter image description here

...

  • Thank you for your help and time. I really appreciate it! This makes sense and seems like it can be implemented into what has been developed so far. – John Nov 8 '18 at 15:41
2

The following setup does what you want. The steps include:

  • Use fancyhdr to set your headers/footers;

  • Define a page style for each component within the ToC, say tocstart for the first page, toccontinued for subsequent pages and tocend for the final page.

  • Use the following code snippet to set the ToC:

    \cleardoublepage
    \begingroup
    \makeatletter
    \let\ps@plain\ps@tocstart
    \makeatother
    \pagestyle{toccontinued}
    \tableofcontents % This will issue \thispagestyle{plain} for the first page
    \thispagestyle{tocend}
    \endgroup
    \cleardoublepage
    

    You first ensure that you're on the appropriate page by issuing \cleardoublepage (this will be similar to \clearpage if you're in oneside mode). Then we open a group \begingroup to limit the scope of a macro change \let\ps@plain\ps@tocstart to just hold for the ToC. This macro change is necessary since the \tableofcontents will issue a \chapter (actually \chapter*, but still) which sets its first page to have the plain page style (using \thispagestyle{plain}). By \letting \ps@plain to \ps@tocstart we ensure that the plain page style is exactly the same as tocstart. \pagestyle{toccontinued} will hold after that. After setting \tableofcontents, we're assured that the first and subsequent pages will have the correct page styles. The final page's style is also set using \thispagestyle{tocend}, after which the group is closed and the page is shipped out (using \cleardoublepage again).

Here is a complete minimal example using the above suggestions:

enter image description here

\documentclass{report}

\usepackage{multido,lipsum}

\usepackage{fancyhdr}

\fancypagestyle{tocstart}{%
  \fancyhf{}% Clear header/footer
  \renewcommand{\headrulewidth}{0pt}% No header rule
  \renewcommand{\footrulewidth}{0pt}% No footer rule
  \fancyhead[R]{\contentsname}% Right header
}
\fancypagestyle{toccontinued}{%
  \pagestyle{tocstart}% Similar to tocstart
  \fancyhead[R]{\contentsname{} (Continued)}% Right header
}
\fancypagestyle{tocend}{%
  \pagestyle{tocstart}% Similar to tocstart
  \fancyhead[R]{\contentsname{} (Concluded)}% Right header
}

\begin{document}

\cleardoublepage
\begingroup
\makeatletter
\let\ps@plain\ps@tocstart
\makeatother
\pagestyle{toccontinued}
\tableofcontents % This will issue \thispagestyle{plain} for the first page
\thispagestyle{tocend}
\endgroup
\cleardoublepage

\sloppy % Just for this example
\multido{\i=1+1}{15}{%
  \chapter{A chapter}\lipsum[1-10]
  \section{First section}\lipsum[11-20]
  \section{Second section}\lipsum[21-30]
  \section{Third section}\lipsum[31-40]
  \section{Final section}\lipsum[41-50]
}

\end{document}

multido and lipsum was used to create a dummy document with a ToC spanning multiple (at least 3) pages.

Of course, the same can be applied for other lists like the LoF, LoT and Bilbiography, each with their own styles.

  • Thank you for your reply and help. I really appreciate it. This also seems like a great solution as well! – John Nov 8 '18 at 15:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.