Page LayoutUnwanted multiple ToC Entries for customized Headings

Information and discussion about page layout specific issues (e.g. header and footer lines, page formats, page numbers).
Post Reply
phitex
Posts: 7
Joined: Wed Apr 18, 2012 12:17 pm

Unwanted multiple ToC Entries for customized Headings

Post by phitex »

Hello all,

to start each section on the left (even) page, use an Image after the section title and start the contents of the section on the next (right, odd) page, I use the following three commands code in the article class.

Code: Select all

%% cleardoublepage always left (even page):
\makeatletter
\renewcommand*\cleardoublepage{\clearpage\if@twoside
  \ifodd\c@page \hbox{}\newpage\if@twocolumn\hbox{}%
  \newpage\fi\fi\fi} 
\makeatother                                                                              
%% section title always on the left:     
\titleformat{\section}[block]
{\cleardoublepage\huge}
{\thesection} 
{1em{}} 
{ | } %% separate section number from section title using '|'
[{\vspace{8cm}\raisebox{2mm}{\includegraphics[width=14cm]{logos/kamelgrau.pdf}}\thispagestyle{empty\
}\newpage\mbox{}}]%%  any image will do
Everything works fine and looks great in the document, except that the section titles now are printed three or four times in the ToC. How can I get rid of all unnecessary ToC entries?

Any Ideas what I did wrong?

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

Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

Unwanted multiple ToC Entries for customized Headings

Post by Stefan Kottwitz »

It seems to be caused by the \newpage command in the formatting arguments. Try without, to verify.

Stefan
LaTeX.org admin
phitex
Posts: 7
Joined: Wed Apr 18, 2012 12:17 pm

Unwanted multiple ToC Entries for customized Headings

Post by phitex »

For the moment I wrote a minimal Ruby script, which modifies my *.toc file. The \newpage has to cause a new page, but I will give it a try.

thanks.

Code: Select all

#!/usr/bin/ruby

# author: phi@gress.ly
# version: 30. Okt. 2012 V 0.1
#
# Description
#
#   Read a LaTeX - Table of Contents (*.toc) and remove all duplicates
#   entries. Only the first entry is left
#   e.g. From the lines
#      \contentsline {section}{\contentsline {25}Konzepte der Objektorientierung}{13}
#      \contentsline {section}{Konzepte der Objektorientierung}{13}
#      \contentsline {section}{Konzepte der Objektorientierung}{14}
#      \contentsline {section}{Konzepte der Objektorientierung}{15}
#   only the first line will remain
#

def main()
  lastLine = ""
  line     = STDIN.gets

  while(line)
    
    if(isDuplicate(lastLine, line))
      line = STDIN.gets
    else
      print line
      lastLine = line
      line     = STDIN.gets
    end
  end
  
end


def isDuplicate(l1, l2)

  treffer1 = l1.match("\\\\contentsline \\{section\\}\\{\\\\numberline \\{[^\\}]*\\}([^\\}]*)\\}\\{([0-9]*)\\}")
  if(treffer1)
    title1 = treffer1[1].strip
  end


  treffer2 = l2.match("\\\\contentsline \\{section\\}\\{([^\\}]*)\\}\\{([0-9]*)\\}")
  if(treffer2)
    title2 = treffer2[1].strip
  end

  if(treffer1 && treffer2)
    return title1 == title2;
  else
   return false
  end

end

main()
Post Reply