Page LayoutControlling page numbering in toc

Information and discussion about page layout specific issues (e.g. header and footer lines, page formats, page numbers).
Post Reply
eskrut
Posts: 2
Joined: Thu Sep 09, 2010 10:43 pm

Controlling page numbering in toc

Post by eskrut »

Hi,

I need to add a lot of sections to my toc, where each section has a different page number.

The hard way is to make a new page for each section, but as my sections are empty, I would like to avoid these extra pages.

I'm looking for something like this:

Code: Select all

\addcontentsline{toc}{section}{section title}
but where I also can enter the page number.

Can anyone help me?
Thanks

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

frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am

Controlling page numbering in toc

Post by frabjous »

I'm a bit perplexed by why it is necessary to specify the page numbers manually. A minimal working example would be helpful.

How do these "sections" appear in the document? With the starred \section*{...} command? If so, then consider using:

Code: Select all

\phantomsection%
\addcontentsline{toc}{section}{name of section}%
\section*{name of section}
If it is really necessary for some reason to specify the page numbers manually, then I guess you could use the \addtocontents command instead of \addcontentsline. Exactly the right syntax to use here would depend quite a bit on your document class and what packages, if any, are being used to format the table of contents. You might be able to get a sense of the right format by looking at the .aux file being generated. But for a relatively plain document in the article class, then something like:

Code: Select all

\addtocontents{toc}{\contentsline{section}{\numberline{9}Section Title}{15}}
Here, "9" is the section number, and "15" the page number. You could change "{9}" to "{}" to make the section number blank, and change 15 to whatever.

That seems to work for the article class with an otherwise untouched table of contents; no guarantees it would work elsewhere.
eskrut
Posts: 2
Joined: Thu Sep 09, 2010 10:43 pm

Re: Controlling page numbering in toc

Post by eskrut »

Thanks for you reply, frabjous.

\addtoctontents was exactly the line I was looking for. I use report class, though, so I'm having some problems making it work. But I'm working on it :)

Just for enlightenment. This problem is a minor part of a bigger problem. I want to make cross reference between two different documents, and make chapters and sections etc. in one document appear in the toc of the second document.

So, that why I need \addtoccontents. However, I'm not quite sure if this is the right approach.
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Controlling page numbering in toc

Post by gmedina »

eskrut wrote:...
Just for enlightenment. This problem is a minor part of a bigger problem. I want to make cross reference between two different documents, and make chapters and sections etc. in one document appear in the toc of the second document...
Then it seems that you could use the pdfpages and/or (it's not clear to me if you want to merge the documents) xr packages to automate the process and prevent mistakes produced by your "manual" current approach.
1,1,2,3,5,8,13,21,34,55,89,144,233,...
Post Reply