I'm writing a book, and I would like to have (relatively?) fine-grained control of what numbers are printed in the TOC.
- No numbers printed for chapters, only their names.
- Section numbers printed for sections, but not their chapter numbers.
- Nothing printed for subsections or below.
I've solved 1 by manually adding chapters to the TOC using \addcontentsline{toc}{chapter}{Chapter Title}
and then manually running stepcounter{chapter}
. I've solved 3 by using \setcounter{tocdepth}{1}
.
But I'm unsure of how to fix 2. Current results look like this:
I would like to remove the chapter numbers from the sections, so that, e.g., it was just 1, 2, 3, 4 in the Introduction rather than 1.1, 1.2 and so on. (The Commentary chapter should work the same way. In the Text chapter, it's irrelevant as there are no sections there.)
I'll mention two other things. First, the code I have already feels like Rube Goldberg contraption. I do one thing to keep chapter headings from printing in the text in order that I can print them in a custom manner. Then I do a different thing to suppress default section printing and control how section headings look in the text. So my MWE may be a bit of a mess: sorry for that. Second, whatever I'm doing already seems to cause hyperref
to break. Only subsection links work. I suspect that's because I'm manually adding the chapter names. If anyone has a suggestion for that, I would appreciate it.)
MWE:
\documentclass[11pt,letterpaper,oneside]{book}
\renewcommand\section{\@startsection {section}{1}{\z@}{0ex}{0ex}{\@gobble}}
\usepackage{titlesec}
\usepackage[extramarks]{titleps}
\newcounter{firstLine}
\setcounter{firstLine}{1}
\newmarkset{firstLine}
\newextramark*{firstLine}{firstLine}
\newcommand*\topfirstLine{\topextramarks{firstLine}{\arabic{firstLine}}}
\newcommand*\botfirstLine{\botextramarks{firstLine}{\arabic{firstLine}}}
\titleformat{\section}{\centering\normalfont\itshape}{}{0em}{}
\titleformat{\subsection}[runin]{\normalfont\bfseries}{}{0em}{}
\newpagestyle{toc}{%
\sethead[]% even-left
[CONTENTS]% even-center
[]% even-right
{}% odd-left
{CONTENTS}% odd-center
{}% odd-right
\setfoot{}%left
{\thepage}%center
{}%right
}
\newpagestyle{introduction}{%
\sethead[]% even-left
[INTRODUCTION: \sectiontitle]% even-center
[]% even-right
{}% odd-left
{INTRODUCTION: \sectiontitle}% odd-center
{}% odd-right
\setfoot{}%left
{\thepage}%center
{}%right
}
\newpagestyle{text}{%
\sethead[]% even-left
[ODYSSEY BOOK 1]% even-center
[]% even-right
{}% odd-left
{ODYSSEY BOOK 1}% odd-center
{}% odd-right
\setfoot{}%left
{\thepage}%center
{}%right
}
\newpagestyle{commentary}{%
\sethead[]% even-left
[COMMENTARY:~%
\edef\tempa{\topfirstLine}\edef\tempb{\botfirstLine}%
\topfirstLine\ifx\tempa\tempb\relax\else--\botfirstLine\fi]% even-center
[]% even-right
{}% odd-left
{COMMENTARY:~%
\edef\tempa{\topfirstLine}\edef\tempb{\botfirstLine}%
\topfirstLine\ifx\tempa\tempb\relax\else--\botfirstLine\fi}% odd-center
{}% odd-right
\setfoot{}%left
{\thepage}%center
{}%right
}
\newcommand{\chap}[1]{%
\addcontentsline{toc}{chapter}{#1}%
\stepcounter{chapter}%
}
\usepackage{hyperref}
% -]]
% [[- Document-
\begin{document}
\begin{titlepage}
\begin{center}
\huge Homer's \textit{Odyssey} Book 1
\newpage
\end{center}
\end{titlepage}
\pagenumbering{roman}
\pagestyle{toc}
\setcounter{tocdepth}{1} % Don't show subsections in the TOC
\renewcommand\contentsname{} % Don't print a section title for TOC
\tableofcontents
\addtocontents{toc}{% Print a header that conforms to book's overall style
\centerline{\textbf{\large C\,O\,N\,T\,E\,N\,T\,S}}%
\bigskip%
\hrule%
\bigskip%
}
\pagenumbering{arabic}
\pagestyle{introduction}
\clearpage
\chap{Introduction}
\thispagestyle{empty}
\centerline{\textbf{\large I\,N\,T\,R\,O\,D\,U\,C\,T\,I\,O\,N}}
\bigskip
\hrule
\bigskip
\section{Book 1 in the structure of the Odyssey}
Stuff about structure of the poem here.
\section{Characters}
Stuff about characters goes here.
\section{Homeric Greek}
Lots of information about Homeric Greek goes here.
\section{About The Text}
Notes about the text of the poem.
\pagestyle{text}
\clearpage
\chap{Odyssey Book 1}
\thispagestyle{empty}
\centerline{\textbf{\large O\,D\,Y\,S\,S\,E\,Y\,\ B\,O\,O\,K\ 1}}
\bigskip
\hrule
\bigskip
Text of the poem goes here.
\pagestyle{commentary}
\clearpage
\chap{Commentary}
\thispagestyle{empty}
\centerline{\textbf{\large C\,O\,M\,M\,E\,N\,T\,A\,R\,Y}}
\bigskip
\hrule
\bigskip
\section{1--10 Proem}
Commentary goes here.
\end{document}
titlesec
andtitleps
. Would require some changes to cleanly use KOMA.