Page Layout ⇒ Adding a heading to the table of contents
Adding a heading to the table of contents
I need to add a heading to the TOC as the image below:
Thanks
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
- Stefan Kottwitz
- Site Admin
- Posts: 10324
- Joined: Mon Mar 10, 2008 9:44 pm
Adding a heading to the table of contents
you can use this:
Code: Select all
\usepackage{afterpage}
\newcommand*{\headline}{%
\hbox to \linewidth{\underline{Title}\hfill\underline{Page}}
\bigskip\afterpage{\headline}}
\addtocontents{toc}{\protect\headline}
Adding a heading to the table of contents
Perfect!. Thank you so much, Stefan.Stefan Kottwitz wrote:Hi nadaa,
you can use this:
StefanCode: Select all
\usepackage{afterpage} \newcommand*{\headline}{% \hbox to \linewidth{\underline{Title}\hfill\underline{Page}} \bigskip\afterpage{\headline}} \addtocontents{toc}{\protect\headline}
There is a problem, this is repeated on all the pages, and multiple empty pages were created!?
I still need to set the font size for "Table of Content" to be 16px and centered.
chapter font size within the TOC to be 14px bold and section 12px bold.
How can I do that?
I use a report class doc.
- Stefan Kottwitz
- Site Admin
- Posts: 10324
- Joined: Mon Mar 10, 2008 9:44 pm
Adding a heading to the table of contents
Stefan
Adding a heading to the table of contents
Hi Stefan. I am working on a large document (thesis). My question is about formatting table of content. What shall I show?Stefan Kottwitz wrote:Please post a minimal but compilable example of your code. It takes too much time to imagine and create some code, that may be similar to what you wrote, or not... no way to test without your code.
Stefan
The previous solution you gave works, but the heading was copied to the whole doc, besides, it adds multiple empty pages?!
- Stefan Kottwitz
- Site Admin
- Posts: 10324
- Joined: Mon Mar 10, 2008 9:44 pm
Adding a heading to the table of contents
Code: Select all
\usepackage{afterpage}
\newif\iftoc
\newcommand*{\headline}{%
\hbox to \linewidth{\normalfont\underline{Title}\hfill\underline{Page}}
\bigskip\afterpage{\iftoc\headline\fi}}
\addtocontents{toc}{\protect\headline}
...
\begin{document}
...
{\toctrue\tableofcontents}
Adding a heading to the table of contents
Thanks, I tried it, but the same.Stefan Kottwitz wrote:Then use it this way:
StefanCode: Select all
\usepackage{afterpage} \newif\iftoc \newcommand*{\headline}{% \hbox to \linewidth{\normalfont\underline{Title}\hfill\underline{Page}} \bigskip\afterpage{\iftoc\headline\fi}} \addtocontents{toc}{\protect\headline} ... \begin{document} ... {\toctrue\tableofcontents}
When I delete \toctrue, the heading appears on the first page of TOC only, not on the rest of TOC pages!
- Stefan Kottwitz
- Site Admin
- Posts: 10324
- Joined: Mon Mar 10, 2008 9:44 pm
Adding a heading to the table of contents
Are you sure that you did not omit the braces? They are required, they keep the change local. Eithernadaa wrote:Thanks, I tried it, but the same.
{\toctrue\tableofcontents}
or
\toctrue
\tableofcontents
\tocfalse
should work.
Stefan
Adding a heading to the table of contents
Yes, it works. I forgot the brackets.Stefan Kottwitz wrote:Are you sure that you did not omit the braces? They are required, they keep the change local. Eithernadaa wrote:Thanks, I tried it, but the same.
{\toctrue\tableofcontents}
or
\toctrue
\tableofcontents
\tocfalse
should work.
Stefan
Thank you

How I can learn all these stuff. I have been using Latex for a while, but I can't solve problems without asking!. Any suggestion?.
- Stefan Kottwitz
- Site Admin
- Posts: 10324
- Joined: Mon Mar 10, 2008 9:44 pm
Adding a heading to the table of contents

Experience comes over time. You can simply ask about any LaTeX problem here, that's the purpose of the forum. Once we talked about it and posted a fix, other people have a good chance to find it via google. So, asking questions helps other people too. Reading answers then also adds knowledge over time. Often solutions are quick hacks that show how to manually fix things.

Stefan