I'm curious if there is a way to have another "column" of numbers in the Table of Contents. The book I'm trying to typeset has a column of chapter and section titles, a corresponding column of subsection number-ranges and a corresponding column of page numbers. So, for example, for chapter one section one, which has subsections one through five on it, and is on page 2, the line would read:
1.1 Section Title ….. 1-5 … 2
I've looked at the memoir
and titletoc
documentation, but to no avail. The output should look something like this:
Best Answer
One can do this with
etoc
, although it is not entirely straightforward.A revised version is added at the bottom of the answer: it simplifies the coding a bit, and tries hard to get even closer to the original. Note that in the code here the
\bfseries
inside the\textsc
does not work:But with T1 encoding it works, so I use it in the second proposal.
Unfortunately the
\etocnumber
macro is not something to which one can apply\arabic
or\Roman
. So one has to make sure that the number is registered in the .toc file in the desired format. Renewing\thechapter
does it.I also took advantage of the
memoir
command\counterwithout
which was very handy here to get the sections numbered as desired (I had to go into thememoir
manual as I am not familiar with that class).Finally, I had to manually put in the toc file the unnumbered chapters with some
\addcontentsline
commands.Setting up the
etoc
styles for part, chapter and section was a bit subtle and I used one or two tricks to get the desired look.Update: some explanations on the code.
With
etoc
one specifies a style for each sectioning level actually to be displayed in the TOC, so here part, chapter, section. The command\etoctoclines
will use the package pre-defined styles, but here we need to redefine all of them (part, chapter, and section). Even when it is not clearly a requirement as here to redefine all styles, it is often a necessity as the pre-defined styles for example expect to start in 'vertical mode', and this puts a constraint on what one redefines. So typically one has to redefine all styles used (the pre-defined styles can be customized as explained in the manual, rather than redefined).So one does
\etocsetstyle{part or chapter or section}{A}{B}{C}{D}
whereBC
is executed for each part, chapter, or section, and A is executed once at the beginning and D once at the end. This means that the first section in a chapter (or in a part if there was no chapter in-between) excutes A and B and C, the last in the chapter executes B and C and D, and the others do B and C.The B and C parts are supposed to be built up with
\etocname
,\etocnumber
and\etocpage
. When hyperref is present they all are hyperlinks (for the page number, iflinktoc=all
was an hyperref option). The reason for a separate B and C is that sometimes one wishes to skip the B of the first section. For this one ends the A with the command\etocskipfirstprefix
.Here the B for the section line style is used to do a trick: it is set up to
gobble
the C, but as we used\etocskipfirstprefix
the result is that all section numbers are indeed gobbled except the first one. And the D of the last section then puts in the missing (gobbled) final section number. The A opened a box which is then closed by D, and printed by D. This is to use a colorbox to erase the dots which were printed before by the style for chapter...The codes for part and chapter do some tricks to add 'extra decorations' to the table of contents, interrupting its normal flow to set up the
Lessons
,Sections
andPage
headings.The reason for the
\unskip
after\etocname
in the chapter line style is thatetoc
uses the packagexspace
and that each of\etocname
,\etocnumber
and\etocpage
ends with an\xspace
. Sometimes one has to cancel its effect, and it seems to be the case before leaders.Above I discussed the 'line styles', now there is the matter of the title of the TOC and its global style: is it printed in one or two columns? does it add its name to the .toc file? etc...
Here I used (I didn't give much thought to it, some other package commands which could have been suitable) the
\etocruledstyle
command, with argument[1]
to say we are on one column (the default is two). The reason to use the command is that it centers its argument, not for the 'rule' in its name: normally the command puts two horizontal rules on each side, but here using a parbox of maximal width we canceled these rules. And then a rule is explicitely added to the definition of the parbox.Overall, the code uses a lot of
TeX
looking things, the reason is simple, I never remember theLaTeX
commands for boxes and rules, and I have often problems when I try to use them, so I always end up going back to\hbox
and\rule
...Note: the trick to erase previous things by putting a colored box on it is not perfect; it seems to depend then on the PDF viewer used. In Acrobat, ok, but on mac os, with Skim the dots survive, although faintly.
Probably some transparency problem, I think I have seen it discussed elsewhere.Actually using
\fboxsep1pt
and not\fboxsep0pt
before\colorbox
solves this. I am not sure I understand why it did not work already with\fboxsep0pt
.Anyway the outcome, un-trimmed to compare to the OP's original: