Document ClassesFormating the TOC

Information and discussion about specific document classes and how to create your own document classes.
Post Reply
yago
Posts: 29
Joined: Sat Dec 13, 2008 6:40 pm

Formating the TOC

Post by yago »

After the help of Javier Bezos and Keta, I have now this code for my document and TOC:

Code: Select all

\documentclass[spanish]{book}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}

\makeatletter
\usepackage[left=3.5cm,right=3cm,top=2.5cm,bottom=2.5cm]{geometry}
\usepackage{fnpos}
\usepackage{ifthen}
\usepackage{graphicx}
\graphicspath{{C:/lyx/graficos/}}
\usepackage{wrapfig}
\usepackage{picins}
\usepackage{wasysym}
\usepackage{marvosym}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{nicefrac}
\usepackage{upgreek}
\usepackage{txfonts}
\usepackage{textcomp}
\usepackage[a]{esvect}
\usepackage{nccparskip}
\usepackage[lflt]{floatflt}
\usepackage[font=small,labelfont=bf,justification=centering]{caption}
\usepackage[spanish]{babel}
\usepackage{subfigure}
\usepackage{subdepth}
\usepackage{array}
\usepackage{booktabs}
\usepackage{multirow}
\usepackage{tocvsec2}
\usepackage{multicol,ragged2e}
\setlength\columnseprule{0.4pt}
\addtolength\columnsep{10pt}

\usepackage{titlesec}
\usepackage{titletoc}

\addto\captionsspanish{\renewcommand{\contentsname}{\bfseries\rm\Huge{\'Indice}}}
\addto\captionsspanish{\renewcommand{\partname}{Cap\'itulo}}
\addto\captionsspanish{\renewcommand{\chaptername}{Lecci\'on}}

\titleformat{\part}[block]
{\filcenter\bfseries\Huge}
{\bfseries\Huge\scshape{\partname}\hspace{1pc}\bfseries\Huge\scshape{\thepart}{.}\bfseries\Huge\itshape}
{1pc}
{}

\titleformat{\chapter}[block] 
{\filcenter\bfseries\Large\scshape} 
{\bfseries\Large\scshape{\chaptertitlename} \bfseries\Large\scshape{\thechapter}\bfseries\Large{\rm\textordfeminine.---}}
{1ex} 
{}

\titlecontents{part} [0pt]
{\addvspace{2.2pc}\contentsmargin{0pt}\centering\rightskip 1.5pc plus 1fil\leftskip\rightskip}
{}
{\Large\scshape\bfseries{Cap\'itulo }}
{\\[-\baselineskip]\hspace*{\fill}\Large\bfseries\thecontentspage\hspace*{-1.5pc}}
[\begin{center}\addvspace{-.8pc}\rule{0.2\linewidth}{1pt}\end{center}]

\titlecontents{chapter}[56pt]
{\addvspace{1pc}\scshape}
{\contentsmargin{5pt}\bfseries\makebox[0pt][r]{\large\scshape{Lecci\'on}\hspace{.3pc}\large\thecontentslabel{.}\enspace}\large}
{\contentsmargin{0pt}\large}{\titlerule*[0.5pc]{.}\large\bfseries\contentspage}
[\addvspace{-1.5pc}] 
\usepackage[breaklinks]{hyperref}

\makeatother

\begin{document}

\end{document}
The book is builded with a serie of 60 \include commands, from the first file that is a page before the "Introducción" (is a part*) to the last that is "Apéndice" (another part*) and 58 lessons ("Lección XX", these are chapters) between this two files.

The problem that I have now is that in the TOC appears "Capitulo Introducción" and not only "Introducción", in according with the global part formatting. And I dont'n know how manage this problem. In adition, after the first TOC page, that appears an enormous header with the word "ÍNDICE", in bold face and Huge, at right or left that depends on the page is odd or even. I attach an example. Tank you for your help.
Attachments
indice.jpg
indice.jpg (55.64 KiB) Viewed 2277 times

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

phi
Posts: 577
Joined: Tue Oct 21, 2008 8:10 pm

Re: Formating the TOC

Post by phi »

For the first problem:
Probably you'll have to write the \titlecontents command directly into the toc file (using \addcontentsline) before and after the Introduction chapter, first without the prefix, then with the prefix.

For the second problem:
Don't use font commands for commands like \contentsname, they are supposed to contain simple strings because their formatting depends on the context. To change the title format for one chapter, put suitable \titleformat commands before and after this chapter.
Post Reply