Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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:

an example of the TOC I'm trying to create: columns for 1) chapter number and name, 2) Sections, 3) Pages

share|improve this question
1  
It is not clear to me what you want to obtain; could you specify? Maybe add a minimal (not) working example, or a picture? –  Ipsen Nov 18 '12 at 15:42
    
Sorry for the delay! And thanks for your question; I just updated the post with a picture for clarification. –  camatkara Dec 17 '12 at 3:56
    
I would say it is doable, but will take a lot of work. Not something that comes out of the box with any package I've heard of. You would need to recode the \l@... macros, and how would the lesson entries know about the sections in it? I've got some ideas, but no time to implement. –  daleif Dec 17 '12 at 9:44
    
Thanks for the informative reply. After so many views and no solutions, I was figuring as much. It is probably a sign of my newbie-ness that I'm surprised chapters wouldn't know the section-spans within them and that this kind of flexibility in a TOC isn't possible without major recoding. Thanks for letting me know. –  camatkara Dec 17 '12 at 15:03
    
Here is a related question, which shows that it won't be easy. Displaying the range of sections on the page in the header. –  Alan Munn Dec 20 '12 at 15:28
show 4 more comments

1 Answer

up vote 13 down vote accepted

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:

Font shape `OT1/cmr/bx/sc' undefined 
using `OT1/cmr/bx/n' instead

But with T1 encoding it works, so I use it in the second proposal.

\documentclass{memoir}

\renewcommand{\thechapter}{\Roman{chapter}}
\counterwithout{section}{chapter}

\usepackage{etoc}
\usepackage{color}

% \usepackage[linktoc=all]{hyperref} % try it, it works!
% \etoctoclines  % removed as it is unnecessary: styles for part, 
                 % chapter, and section are entirely re-defined below

\renewcommand\etoctoclineleaders{\hbox to .12\linewidth{\hss...\hss}}
\newif\iffirstextradone
\newif\ifsecondextradone

\etocsetstyle{part}
{}
{}
{\begin{center}\Large\bfseries PART \etocnumber
\ifsecondextradone\\\etocname.\fi\end{center}
\iffirstextradone\else
\mbox{}\hskip.72\linewidth\hbox to .23\linewidth
    {\textsc{\bfseries Sections.\hss Page.}}\par\fi
\firstextradonetrue}
{}

\etocsetstyle{chapter}
{}
{\par\noindent\etocifnumbered{\makebox[.1\linewidth][r]
    {\bfseries\etocnumber.}}{\hspace*{.1\linewidth}}}
{\hbox to .7\linewidth
    {\hspace{1em}\etocname\unskip\leaders\etoctoclineleaders\hss}%
\hbox to .15\linewidth{\hss\ifsecondextradone\etocifnumbered\etocpage%
{}\else\etocpage\fi}%
\hskip-.3\linewidth\leaders\etoctoclineleaders\hskip.2\linewidth
\hskip-.1\linewidth}
{}

\newbox\forsectionnumbers
\makeatletter
\etocsetstyle{section}
{\setbox\forsectionnumbers=\hbox to .1\linewidth
    \bgroup\hss\etocskipfirstprefix}
{\@gobble}
{\etocnumber---}
{\etocnumber\hss\egroup\colorbox{white}{\box\forsectionnumbers}\par
\ifsecondextradone\else
\begin{center}\bfseries Concord.\end{center}
\noindent \textsc{\bfseries Lesson.}\par\fi\secondextradonetrue
}
\makeatother

\begin{document}

\etocruledstyle[1]{\parbox{\linewidth}{\centering
\textsc{\Huge\MakeUppercase{Table of Contents}}\\
\rule{.2\linewidth}{2pt}}}

\tableofcontents*

\part{}

\chapter*{Introductory}
\addcontentsline{toc}{chapter}{Introductory}

\newcount\tempcount

\loop\advance\tempcount by 1
\section{This is}
section \the\tempcount
\ifnum\tempcount<8
\repeat

\chapter{Concord of Subject and Verb}

\loop\advance\tempcount by 1
\section{This is}
section \the\tempcount
\ifnum\tempcount<17
\repeat

\chapter{Concord of Substantive and Adjective}

\loop\advance\tempcount by 1
\section{This is}
section \the\tempcount
\ifnum\tempcount<22
\repeat

\chapter*{Concord of Relative and its Antecedent}
\addcontentsline{toc}{chapter}{Concord of Relative and its Antecedent}

\loop\advance\tempcount by 1
\section{This is}
section \the\tempcount
\ifnum\tempcount<25
\repeat

\part{Government}

\chapter{The Accusative Case}

\chapter*{General uses}
\addcontentsline{toc}{chapter}{General Uses}

\loop\advance\tempcount by 1
\section{This is}
section \the\tempcount
\ifnum\tempcount<30
\repeat

\chapter*{Particular uses}
\addcontentsline{toc}{chapter}{Particular Uses}

\loop\advance\tempcount by 1
\section{This is}
section \the\tempcount
\ifnum\tempcount<37
\repeat

\chapter{Verbs governing two Accusatives}

\loop\advance\tempcount by 1
\section{This is}
section \the\tempcount
\ifnum\tempcount<41
\repeat

\chapter{The Causal}

\loop\advance\tempcount by 1
\section{This is}
section \the\tempcount
\ifnum\tempcount<49
\repeat

\chapter{The Instrumental Case}

\chapter*{General uses}
\addcontentsline{toc}{chapter}{General Uses}

\loop\advance\tempcount by 1
\section{This is}
section \the\tempcount
\ifnum\tempcount<54
\repeat

\chapter*{Particular uses}
\addcontentsline{toc}{chapter}{Particular Uses}

\loop\advance\tempcount by 1
\section{This is}
section \the\tempcount
\ifnum\tempcount<59
\repeat

\chapter{The Dative Case}

\chapter*{General uses}
\addcontentsline{toc}{chapter}{General Uses}

\loop\advance\tempcount by 1
\section{This is}
section \the\tempcount
\ifnum\tempcount<65
\repeat

\chapter*{Particular uses}
\addcontentsline{toc}{chapter}{Particular Uses}

\loop\advance\tempcount by 1
\section{This is}
section \the\tempcount
\ifnum\tempcount<71
\repeat

\chapter{The Ablative Case}

\chapter*{General uses}
\addcontentsline{toc}{chapter}{General Uses}

\loop\advance\tempcount by 1
\section{This is}
section \the\tempcount
\ifnum\tempcount<75
\repeat

\chapter*{Particular uses}
\addcontentsline{toc}{chapter}{Particular Uses}

\loop\advance\tempcount by 1
\section{This is}
section \the\tempcount
\ifnum\tempcount<86
\repeat

\chapter{The Locative Case}

\chapter*{General uses}
\addcontentsline{toc}{chapter}{General Uses}

\loop\advance\tempcount by 1
\section{This is}
section \the\tempcount
\ifnum\tempcount<92
\repeat

\chapter*{Particular uses}
\addcontentsline{toc}{chapter}{Particular Uses}

\loop\advance\tempcount by 1
\section{This is}
section \the\tempcount
\ifnum\tempcount<100
\repeat

\end{document}

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 the memoir 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} where BC 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, if linktoc=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 and Page headings.

The reason for the \unskip after \etocname in the chapter line style is that etoc uses the package xspace 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 the LaTeX 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...

nice table of contents

\documentclass[letterpaper]{memoir}
\usepackage[T1]{fontenc}
%\usepackage{layout}
% I am just ignorant of the memoir commands to set up
% the page parameters. I just want my text centered on the page.
\setlength{\textwidth}{5.5in}
\setlength{\oddsidemargin}{.5in}
\setlength{\evensidemargin}{.5in}

\renewcommand{\thechapter}{\Roman{chapter}}
\counterwithout{section}{chapter}

\usepackage{etoc}
\usepackage{color}
% \usepackage[linktoc=all]{hyperref}

\newif\ifextraidone
\newif\ifextraiidone

\etocsetstyle{part}
{}
{}
{\begin{center}\Large\bfseries PART \etocnumber
\ifextraiidone\\\etocname.\fi\end{center}
\ifextraidone\else
\noindent\hskip.7\linewidth
    \hbox to .2\linewidth
    {\hss\small\textsc{\bfseries Sections.\ Page.}}\par\fi
\extraidonetrue
}
{}

\newcommand\mytocleaders{\hbox to .125\linewidth{...\hss}}
\etocsetstyle{chapter}
{}
{\par\noindent\etocifnumbered
    {\makebox[.15\linewidth][r]{\bfseries\etocnumber.}}
    {\hspace*{.15\linewidth}}}
{\hbox to .65\linewidth
    {\hspace{1em}\etocname\unskip\leaders\mytocleaders\hss}%
 \hskip-.1\linewidth
 \hbox to .2\linewidth{\hspace{1.5em}...\hss
                \etocifnumbered
                    {\etocpage}
                    {\ifextraiidone\else\etocpage\fi}}%
 \hskip-.2\linewidth
}
{}

\newbox\forsectionnumbers
\makeatletter
\etocsetstyle{section}
{\setbox\forsectionnumbers=\hbox to .1\linewidth
    \bgroup\hss\etocskipfirstprefix}
{\@gobble}
{\etocnumber---}
{\etocnumber\egroup
% for reasons I do not quite understand, in some pdf viewers the dots
% do not completely disappear if here \fboxsep0pt is used.
    \fboxsep1pt\colorbox{white}{\box\forsectionnumbers}\par
    \ifextraiidone\else
        \begin{center}\bfseries Concord.\end{center}
        \noindent\makebox[.15\linewidth][r]{\textsc{\bfseries Lesson.}}\par
    \fi\extraiidonetrue
}
\makeatother

\begin{document}%\layout

\renewcommand{\etocinnertopsep}{0pt}

\etocruledstyle[1]{%
    \parbox{\linewidth}{%
        \centering
        \textsc{\bfseries\LARGE\MakeUppercase{Table of Contents}}\\
        \rule{.2\linewidth}{2pt}}%
}

\tableofcontents*

\part{}

\chapter*{Introductory}
\addcontentsline{toc}{chapter}{Introductory}

\newcount\tempcount

\loop\advance\tempcount by 1
\section{This is}
section \the\tempcount
\ifnum\tempcount<8
\repeat

\chapter{Concord of Subject and Verb}

\loop\advance\tempcount by 1
\section{This is}
section \the\tempcount
\ifnum\tempcount<17
\repeat

\chapter{Concord of Substantive and Adjective}

\loop\advance\tempcount by 1
\section{This is}
section \the\tempcount
\ifnum\tempcount<22
\repeat

\chapter*{Concord of Relative and its Antecedent}
\addcontentsline{toc}{chapter}{Concord of Relative and its Antecedent}

\loop\advance\tempcount by 1
\section{This is}
section \the\tempcount
\ifnum\tempcount<25
\repeat

\part{Government}

\chapter{The Accusative Case}

\chapter*{General uses}
\addcontentsline{toc}{chapter}{General Uses}

\loop\advance\tempcount by 1
\section{This is}
section \the\tempcount
\ifnum\tempcount<30
\repeat

\chapter*{Particular uses}
\addcontentsline{toc}{chapter}{Particular Uses}

\loop\advance\tempcount by 1
\section{This is}
section \the\tempcount
\ifnum\tempcount<37
\repeat

\chapter{Verbs governing two Accusatives}

\loop\advance\tempcount by 1
\section{This is}
section \the\tempcount
\ifnum\tempcount<41
\repeat

\chapter{The Causal}

\loop\advance\tempcount by 1
\section{This is}
section \the\tempcount
\ifnum\tempcount<49
\repeat

\chapter{The Instrumental Case}

\chapter*{General uses}
\addcontentsline{toc}{chapter}{General Uses}

\loop\advance\tempcount by 1
\section{This is}
section \the\tempcount
\ifnum\tempcount<54
\repeat

\chapter*{Particular uses}
\addcontentsline{toc}{chapter}{Particular Uses}

\loop\advance\tempcount by 1
\section{This is}
section \the\tempcount
\ifnum\tempcount<59
\repeat

\chapter{The Dative Case}

\chapter*{General uses}
\addcontentsline{toc}{chapter}{General Uses}

\loop\advance\tempcount by 1
\section{This is}
section \the\tempcount
\ifnum\tempcount<65
\repeat

\chapter*{Particular uses}
\addcontentsline{toc}{chapter}{Particular Uses}

\loop\advance\tempcount by 1
\section{This is}
section \the\tempcount
\ifnum\tempcount<71
\repeat

\chapter{The Ablative Case}

\chapter*{General uses}
\addcontentsline{toc}{chapter}{General Uses}

\loop\advance\tempcount by 1
\section{This is}
section \the\tempcount
\ifnum\tempcount<75
\repeat

\chapter*{Particular uses}
\addcontentsline{toc}{chapter}{Particular Uses}

\loop\advance\tempcount by 1
\section{This is}
section \the\tempcount
\ifnum\tempcount<86
\repeat

\chapter{The Locative Case}

\chapter*{General uses}
\addcontentsline{toc}{chapter}{General Uses}

\loop\advance\tempcount by 1
\section{This is}
section \the\tempcount
\ifnum\tempcount<92
\repeat

\chapter*{Particular uses}
\addcontentsline{toc}{chapter}{Particular Uses}

\loop\advance\tempcount by 1
\section{This is}
section \the\tempcount
\ifnum\tempcount<100
\repeat

\end{document}

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:

fine tuned TOC

share|improve this answer
    
+1 Very nice! I'd not heard of this package before. I assume from your user name that you're the author. If you like, you could add your name to the list of package authors on the site. –  Alan Munn Dec 20 '12 at 20:16
    
@AlanMunn: thanks for the link, I shall do it. –  jfbu Dec 20 '12 at 20:30
    
Wow, this is just terrific. LaTeX and its users continue to blow me away. Thanks so much for making this possible--it's the last link in a long project for me. Many thanks! –  camatkara Dec 21 '12 at 1:32
    
@camatkara glad it helped. Nice to know that the package which I wrote only last month is finding some use. For your challenge, I had problems with my obstination to use \leaders to put into the lines the .... It is very delicate and some other method would be needed to achieve something closer to the original. I added a revised version of the code, with an untrimmed image of the ensuing page. –  jfbu Dec 21 '12 at 11:01
    
The problem with a white box not covering ink underneath seems to be one of anti-aliasing in the Apple PDFkit used (I think) by TeXShop or by Skim and Preview. (I have been told so on c.t.tex). From experimenting, \fboxsep=.25pt enlarges enough the white eraser to actually do its expected job. –  jfbu Dec 21 '12 at 22:03
show 2 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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