4

My school requires tables of contents formatted like this -- please note the little headings, in red: enter image description here

I have it almost ready, except for a pesky misalignment in the second page of the table of contents. "Chapter" gets thrown to the right.

Chapter thrown to right

As I prepare a minimal working example, it seems that a previous addtocontents line triggers the problem.

\documentclass[12pt,letterpaper,oneside]{book}
\usepackage{tocloft}

\usepackage[toc,page]{appendix}
\usepackage{titlesec}
\usepackage[nottoc]{tocbibind}
\usepackage{afterpage}
\usepackage{blindtext}
\usepackage{indentfirst}
\usepackage{fancyhdr}

\begin{document}

\tableofcontents

\addtocontents{toc}{\hfill Page \par}
%  Is this line above the culprit? if commented, Chapter below aligns!

\chapter{Blah blah1}
\section{Basics}
\subsection{Margins}
\blindtext
\section{Blah in section}
\Blindtext
\subsection{More blah for a subsection}
\blindtext 
\begin{figure}
\caption{picture}
\end{figure}
\chapter{Some Blah}
\section{One section}
\blindtext
\chapter{All}
\blindtext
\chapter{the}
\blindtext
\section{Good enough}
\blindtext
\subsection{Better}
\blindtext

\addtocontents{toc}{\protect\afterpage{Chapter\hfill Page \par\medskip}}
% This is how I add those 'headings' to the toc.
% Not well aligned!

\chapter{way}
\section{Please}
\section{Go}
\subsection{Ahead}
\chapter{to}
\chapter{the}
\chapter{very}
\chapter{end}
\chapter{keep}
\section{keep uno}
\section{kep dos}
\chapter{going}
\chapter{more}

\end{document}

This minimal code will produce this:

enter image description here

Is there a way to fix that addtocontents line? or a more sensible way to do it?

Please advise. Thank you in advance!


If it helps, these are some lines from the .toc file:

\contentsline {subsection}{OM as city block distance}{28}
\afterpage {Chapter\hfill Page \par \vspace \medskipamount }
\contentsline {subsection}{Euclideanity of OM and Euclidean transformations}{29}
\contentsline {subsubsection}{Raw and transformed OM as Euclidean}{29}
\contentsline {subsubsection}{Low dimensional Euclidean via MDS}{32}
\contentsline {section}{Distribution of sequences and inter-sequence distances}{34}
\contentsline {subsection}{Distribution of true inter-triple and OM distances}{34}

And this is how it looks like:

enter image description here


Aw, I just added a

\addtocontents{toc}{Chapter\hfill Page \par}
\section{Distribution of sequences and inter-sequence distances}

What a dirty thing.

2

You could try this approach which will certainly need some more modifications in case the ToC is more than two pages long. And perhaps there are some drawbacks which I don't see at the moment.

It uses the »atbegshi« package from the »oberdiek« bundle which allows to add the "headline" quite flexible to the next page of the ToC. If necessary, this can also be applied to the LoF an LoT.

\documentclass[11pt]{report}
\usepackage[T1]{fontenc}
\usepackage[nottoc]{tocbibind}
\usepackage{atbegshi}
\usepackage{blindtext}

\AtBeginDocument{%
  \addtocontents{toc}{%
    \contentsline{chapter}{}{Page}%
    \protect\AtBeginShipoutNext{\contentsline{chapter}{\chaptername}{Page}\vspace{\baselineskip}}%
  }%
  \addtocontents{lof}{\contentsline{chapter}{\figurename}{Page}}%
  \addtocontents{lot}{\contentsline{chapter}{\tablename}{Page}}%
}

\begin{document}
  \tableofcontents
  \listoffigures
  \listoftables
  \addtocontents{toc}{\contentsline{chapter}{\chaptername}{}}

  \blinddocument
  \blinddocument
  \blinddocument
  \blinddocument
\end{document}

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

  • Hi Thorsten, for some reason it complains: (./approval.tex) [2] (./myscsuabstract.tex [3]) [4] (./myscsumain.toc) [5] (./myscsumain.lof ! Missing number, treated as zero. <to be read again> \hbox l.1 ...n }\let \advance \leftskip \@tempdima \hbox {}\penalty \@M \hskip -\l... – Juan Zuluaga Dec 9 '13 at 23:07
  • It must be interacting with some other package. – Juan Zuluaga Dec 9 '13 at 23:41
  • I'm sorry Thorsten, I just don't know enough to track down what the interference is that makes your good code not run in my real case. I just added a dirty solution, a direct write to the toc file at the right place – Juan Zuluaga Dec 10 '13 at 7:22
  • @JuanZuluaga: A remote diagnosis is quite hard. So I suggest that you try to build a minimal example. Use the "build up" method, take my code as starting point and add code from your document step-by-step. Don't take too big steps, just small ones (e.g. one package or command definition after the other). Proceed this way until the problem occurs. Then you have the sample code that you can present here. Furthermore I suggest that you use the \contentsline command like I did to add the ToC entry. – Thorsten Donig Dec 11 '13 at 16:35

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.