GeneralHeader in middle of TOC

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
runderwo
Posts: 3
Joined: Thu Aug 23, 2007 8:58 pm

Header in middle of TOC

Post by runderwo »

My university requires a TOC like this:
Abstract ........................... i
Table of contents..................... ii
...
Glossary.................................. iv
Section
1 Introduction ......................... 1
2 Background ......................... 10
2.1 Details .......................... 12
Bibliography ................................. 659

My question is how do I deal with that Section header in the middle of the TOC? I hoped tocloft would help me, but it doesn't seem to do what I need. What I did was added the section header as \addcontentsline{toc}{part}{SECTION} hoping that I could use tocloft to style it appropriately (I don't use the 'part' entity anywhere else in my document).

The problem I have even with this 'part' hack is that the sections above "Section" are indented as the sections below "Section", but somehow I need those to be flush left. A even more horrible hack would be to add them as subsubsections (which I don't use anywhere else) and style subsubsections appropriately....

Edit: Well, that's what I did. I used tocloft to change the properties of 'subsubsection' for the non-numbered sections, and to change the properties of 'part' for the Section header. Good thing I didn't actually need 'part' or 'subsubsection' anywhere else... does anyone have a better method?

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Header in middle of TOC

Post by gmedina »

runderwo wrote: I hoped tocloft would help me, but it doesn't seem to do what I need

in fact, tocloft does what you need:

Code: Select all

\cftpagenumbersoff{part}
\cftaddtitleline{toc}{part}{Section}{}
1,1,2,3,5,8,13,21,34,55,89,144,233,...
runderwo
Posts: 3
Joined: Thu Aug 23, 2007 8:58 pm

Re: Header in middle of TOC

Post by runderwo »

Well, I was hoping there was a way to insert a TOC line in that way without having to style a class specifically for the purpose. It's okay because I don't use 'part' in this document, but maybe in a future document I'm not so lucky...

I didn't notice the indentation didn't show up in my original post. Sorry about that. Any non-numbered section should be flush left, and any numbered section should be indented.

Is there any way to do that without having to use tocloft to style yet another distinct class for the purpose? Basically, a way to disable TOC indent until a particular section is reached, enable it, then disable it when the last numbered section is passed.
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Header in middle of TOC

Post by gmedina »

The following example does what you need (I believe).

Code: Select all

\documentclass{article}
\usepackage{tocloft}

\renewcommand{\cftpartpagefont}{\bfseries \small}
\renewcommand{\cftpartfont}{\bfseries \small}
\setlength{\cftsecindent}{10pt}%change the sections indentation

\begin{document}

\begin{abstract}
This is the abstract.
\end{abstract}
\addcontentsline{toc}{part}{Abstract}
\clearpage
\tableofcontents
\addcontentsline{toc}{part}{Table of Contents}
\clearpage

\cftpagenumbersoff{part}
\cftaddtitleline{toc}{part}{Section}{}

\section{First section}

\section{Second section}

\begin{thebibliography}{99}
\addcontentsline{toc}{part}{Bibliography}
\bibitem{key1} First Bibitem.
\end{thebibliography}

\end{document} 

Edit: I originally posted a wrong solution.
1,1,2,3,5,8,13,21,34,55,89,144,233,...
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Header in middle of TOC

Post by gmedina »

So, if you don't want to use tocloft, you can generate your TOC like this:

Code: Select all

\documentclass{article}

\makeatletter
\renewcommand{\@dotsep}{200}%get rid of dotted lines for subsections
\makeatother

\begin{document}
\contentsline{section}{\Large Table of contents}{}
\protect\addvspace{35pt}%add space between title and first entry
\contentsline{section}{Abstract}{i}
\contentsline{section}{Table of contents}{ii}
\contentsline{section}{Glossary}{iv}
\contentsline{section}{Section}{}
\contentsline{section}{\numberline{1}Introduction}{1}
\contentsline{section}{\numberline{2}Background}{10}
\contentsline{subsection}{\numberline{2.1}Details}{12}
\contentsline{section}{Bibliography}{659}
\newpage

\end{document}
1,1,2,3,5,8,13,21,34,55,89,144,233,...
Post Reply