Page LayoutAdding a heading to the table of contents

Information and discussion about page layout specific issues (e.g. header and footer lines, page formats, page numbers).
nadaa
Posts: 19
Joined: Sun Nov 20, 2016 8:12 pm

Adding a heading to the table of contents

Post by nadaa »

Hi,

I need to add a heading to the TOC as the image below:
table-of-contents.png
table-of-contents.png (4 KiB) Viewed 6440 times
Thanks

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
User avatar
Stefan Kottwitz
Site Admin
Posts: 10290
Joined: Mon Mar 10, 2008 9:44 pm

Adding a heading to the table of contents

Post by Stefan Kottwitz »

Hi nadaa,

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}
Stefan
LaTeX.org admin
nadaa
Posts: 19
Joined: Sun Nov 20, 2016 8:12 pm

Adding a heading to the table of contents

Post by nadaa »

Stefan Kottwitz wrote:Hi nadaa,

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}
Stefan
Perfect!. Thank you so much, Stefan.
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.
User avatar
Stefan Kottwitz
Site Admin
Posts: 10290
Joined: Mon Mar 10, 2008 9:44 pm

Adding a heading to the table of contents

Post by Stefan Kottwitz »

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
LaTeX.org admin
nadaa
Posts: 19
Joined: Sun Nov 20, 2016 8:12 pm

Adding a heading to the table of contents

Post by nadaa »

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
Hi Stefan. I am working on a large document (thesis). My question is about formatting table of content. What shall I show?
The previous solution you gave works, but the heading was copied to the whole doc, besides, it adds multiple empty pages?!
User avatar
Stefan Kottwitz
Site Admin
Posts: 10290
Joined: Mon Mar 10, 2008 9:44 pm

Adding a heading to the table of contents

Post by Stefan Kottwitz »

Then use it this way:

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}
Stefan
LaTeX.org admin
nadaa
Posts: 19
Joined: Sun Nov 20, 2016 8:12 pm

Adding a heading to the table of contents

Post by nadaa »

Stefan Kottwitz wrote:Then use it this way:

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}
Stefan
Thanks, I tried it, but the same.
When I delete \toctrue, the heading appears on the first page of TOC only, not on the rest of TOC pages!
User avatar
Stefan Kottwitz
Site Admin
Posts: 10290
Joined: Mon Mar 10, 2008 9:44 pm

Adding a heading to the table of contents

Post by Stefan Kottwitz »

nadaa wrote:Thanks, I tried it, but the same.
Are you sure that you did not omit the braces? They are required, they keep the change local. Either

{\toctrue\tableofcontents}

or

\toctrue
\tableofcontents
\tocfalse


should work.

Stefan
LaTeX.org admin
nadaa
Posts: 19
Joined: Sun Nov 20, 2016 8:12 pm

Adding a heading to the table of contents

Post by nadaa »

Stefan Kottwitz wrote:
nadaa wrote:Thanks, I tried it, but the same.
Are you sure that you did not omit the braces? They are required, they keep the change local. Either

{\toctrue\tableofcontents}

or

\toctrue
\tableofcontents
\tocfalse


should work.

Stefan
Yes, it works. I forgot the brackets.
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?.
User avatar
Stefan Kottwitz
Site Admin
Posts: 10290
Joined: Mon Mar 10, 2008 9:44 pm

Adding a heading to the table of contents

Post by Stefan Kottwitz »

Knowing all stuff is not so important. A key is, to know where to look for (documentation), work with source code of packages, just try fixing things. There are good ways to know, such as why and how to build a Infominimal working example - once one understood that, he easily tracks down problems and either fixes them himself with the hacked-down code piece, or post the small code sample to a LaTeX forum such as here. Once a problem can be reproduced and tested, it's usually easy to fix for very experienced people, even without knowing details before.

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
LaTeX.org admin
Post Reply