LaTeX forum ⇒ Page LayoutAdding a heading to the table of contents Topic is solved

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

Postby nadaa » Sun Sep 24, 2017 3:54 pm

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 291 times


Thanks

User avatar
Stefan Kottwitz
Site Admin
Posts: 8531
Joined: Mon Mar 10, 2008 9:44 pm
Location: Hamburg, Germany
Contact:

Postby Stefan Kottwitz » Sun Sep 24, 2017 6:23 pm

Hi nadaa,

you can use this:

  1. \usepackage{afterpage}
  2. \newcommand*{\headline}{%
  3. \hbox to \linewidth{\underline{Title}\hfill\underline{Page}}
  4. \bigskip\afterpage{\headline}}
  5. \addtocontents{toc}{\protect\headline}


Stefan
Site admin

nadaa
Posts: 19
Joined: Sun Nov 20, 2016 8:12 pm

Postby nadaa » Sun Sep 24, 2017 7:12 pm

Stefan Kottwitz wrote:Hi nadaa,

you can use this:

  1. \usepackage{afterpage}
  2. \newcommand*{\headline}{%
  3. \hbox to \linewidth{\underline{Title}\hfill\underline{Page}}
  4. \bigskip\afterpage{\headline}}
  5. \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: 8531
Joined: Mon Mar 10, 2008 9:44 pm
Location: Hamburg, Germany
Contact:

Postby Stefan Kottwitz » Sun Sep 24, 2017 8:05 pm

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
Site admin

nadaa
Posts: 19
Joined: Sun Nov 20, 2016 8:12 pm

Postby nadaa » Sun Sep 24, 2017 8:55 pm

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: 8531
Joined: Mon Mar 10, 2008 9:44 pm
Location: Hamburg, Germany
Contact:

Postby Stefan Kottwitz » Sun Sep 24, 2017 9:30 pm

Then use it this way:

  1. \usepackage{afterpage}
  2. \newif\iftoc
  3. \newcommand*{\headline}{%
  4. \hbox to \linewidth{\normalfont\underline{Title}\hfill\underline{Page}}
  5. \bigskip\afterpage{\iftoc\headline\fi}}
  6. \addtocontents{toc}{\protect\headline}
  7. ...
  8. \begin{document}
  9. ...
  10. {\toctrue\tableofcontents}


Stefan
Site admin

nadaa
Posts: 19
Joined: Sun Nov 20, 2016 8:12 pm

Postby nadaa » Sun Sep 24, 2017 10:18 pm

Stefan Kottwitz wrote:Then use it this way:

  1. \usepackage{afterpage}
  2. \newif\iftoc
  3. \newcommand*{\headline}{%
  4. \hbox to \linewidth{\normalfont\underline{Title}\hfill\underline{Page}}
  5. \bigskip\afterpage{\iftoc\headline\fi}}
  6. \addtocontents{toc}{\protect\headline}
  7. ...
  8. \begin{document}
  9. ...
  10. {\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: 8531
Joined: Mon Mar 10, 2008 9:44 pm
Location: Hamburg, Germany
Contact:

Postby Stefan Kottwitz » Sun Sep 24, 2017 10:32 pm

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
Site admin

nadaa
Posts: 19
Joined: Sun Nov 20, 2016 8:12 pm

Postby nadaa » Sun Sep 24, 2017 10:36 pm

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: 8531
Joined: Mon Mar 10, 2008 9:44 pm
Location: Hamburg, Germany
Contact:

Postby Stefan Kottwitz » Mon Sep 25, 2017 5:47 am

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
Site admin


Return to “Page Layout”

Who is online

Users browsing this forum: No registered users and 2 guests