Table of Contents – How to Add a Date Column to the Table of Contents

table of contentstocloft

The book I am republishing contains the transcriptions of lectures given at a certain date. In the table of content, I need an additional column after the title of the lecture (chapter title), where the date of the lecture is called.

I've tried to use some of the answers here (Add extra columns to table of contents) but that didn't answer my question.

I was trying to figure this out with the tocloft package but not sure how I'm going to get there. I'd like to call the following an MWE, but it's not really working for me so far …

\documentclass{book}
\usepackage[utf8]{inputenc}

\title{test}
\author{name}
\date{now}

\usepackage{tocloft}
\renewcommand{\cftchappresnum}{input?}
\begin{document}

\renewcommand\cftchapdotsep{\cftdotsep}

\tableofcontents

\chapter*{first lecture title}
\addcontentsline{toc}{chapter}{first lecture title}

\chapter*{second lecture title}
\addcontentsline{toc}{chapter}{second lecture title}

\chapter*{third lecture title}
\addcontentsline{toc}{chapter}{third lecture title}

\end{document}

What I'm trying to produce is a ToC like this:

ToC to be republished

I'm at the beginning of this project so happy to also get related advice re structuring/document class use/anything that can get me started in the right direction.

Best Answer

Welcome to TeX.SX! If you are fine with using \addcontentsline to manually insert the entries to your table of contents (as was suggested in your question), you are quite free to insert line breaks and alignments into this macro. For example like this (without the tocloft package actually):

\documentclass{book}
\usepackage[utf8]{inputenc}

\newcommand{\toclineinsert}[3][25mm]{%
    \dotfill\ #2\makebox[#1][l]{#3\dotfill}%
}

\title{test}
\author{name}
\date{now}

\begin{document}

\tableofcontents

\addcontentsline{toc}{chapter}{first lecture title \toclineinsert{4 }{January}}

\addcontentsline{toc}{chapter}{second lecture title \toclineinsert{2nd half }{January}}

\addcontentsline{toc}{chapter}{third lecture title \toclineinsert{February/}{March}}

\addcontentsline{toc}{chapter}{a pretty long fourth lecture title \newline that goes over two lines \toclineinsert{29 or 30 }{March}}

\end{document}

As the dates in the added column are aligned to the name of the month, I came up with a solution that allows you to add stuff to the left and to the right of an imaginary vertical line that runs through the table of contents.

For example, \toclineinsert{4 }{January} would place a 4 and a space (the space is needed) to the left of this line and the word January to the right. The space before the 4 and after January is filled with dots.

The \dotfill macro in gerenal inserts as many dots as needed to shift the stuff that comes next to the very right end of the current line. It functions quite similar to a right-aligned tab stop. If you use this multiple times in the same line, the stuff before, after and between these macros will be spread in such a way that the distances are equal.

The \makebox macro adds a box with a specified width to the output. By default, this width is set to 25mm in the \toclineinsert macro, but you can override this by entering, for example, \toclineinsert[30mm]{4 }{January}. This would shift the word January a bit to the left, but only for this entry, of course.

The red line in the following image is, of course, not part of the output and only illustrates the alignment.

enter image description here

Related Question