2

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.

2
  • 1
    Welcome to TeX.SE!
    – Mensch
    Nov 4, 2021 at 10:39
  • 1
    Thank you (fellow) Mensch! I have a feeling I'm going to be here quite a bit in the coming months...
    – Parvana
    Nov 4, 2021 at 10:43

1 Answer 1

1

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

7
  • Thank you! I will take a closer look at how the \addcontentsline command functions, and where to place it. Can you recommend an easy way of ensuring the neat alignment of all of the date-related additions? It seems you are specifying that here: \newcommand{\toclineinsert}[3][25mm]{% \dotfill\ #2\makebox[#1][l]{#3\dotfill}% }
    – Parvana
    Nov 4, 2021 at 11:47
  • Actually, I designed this macro especially to ensure the alignment. I saw that the alignment is always at the name of the month (or the name of the second month in cases like "February/March"). I added some explanations to my answer. Does this help you? Nov 4, 2021 at 12:01
  • By the way, your use of \addcontentsline is totally fine! Nov 4, 2021 at 12:08
  • 1
    Yes! This totally, totally helps - thank you so much! It's been a while since I last used LaTeX and your elaboration is really helpful. Thank you for providing such a pleasant first experience with reaching out here on TeX.SX!
    – Parvana
    Nov 4, 2021 at 12:45
  • I'm running into some issues now, that I think are connected to the macro you wrote for this answer. Or I should say: to me trying to tweak your macro without fully understanding it. The result I'm looking for is to have just the date inserted on the toc line, but no additinal alignment as per your red line example above. My way of accomplishing this was to write for instance \addchap[tocentry={Exaltation \toclineinsert{\normalfont{ 4 January}}},head={}]{Exaltation}. That worked fine, but then I tried to activate the hyperref package and then everything broke...
    – Parvana
    Dec 12, 2021 at 19:31

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.