Could someone please give me a hint on how the virtual chapter is inserted ine the table of contents in the example below? I've tried to use \addcontentsline
before this virtual chapter, but this splits sections of chapter 1 in the table of contents.
[Tex/LaTex] Customizing table of contents
hyperreftable of contents
Related Solutions
It's definitely not a good idea to define \thesection
with formatting instructions. Also, you want to have \thechapter
to expand to \arabic{chapter}
, so that you need to change its appearance only when typesetting the chapter head.
Here are some changes to your settings. However, I don't like at all the way section and subsection titles are set, but the document is yours.
No redefinition of
\thechapter
,\thesection
and\thesubsection
The
\@makechapterhead
is patched to print\Ordinalstring{chapter}
instead of\thechapter
.Some tidying of the code.
\documentclass[a4paper]{report}
\usepackage[english]{babel}
\usepackage[latin1]{inputenc}
\usepackage[scaled=0.92]{helvet}
\usepackage{mathptmx}
\usepackage[T1]{fontenc}
\usepackage{lipsum}
\usepackage[tracking=true]{microtype}
\usepackage{fmtcount}
\usepackage{etoolbox}
\makeatletter
\patchcmd{\@makechapterhead}
{\thechapter}
{\Ordinalstring{chapter}}
{}{}
\makeatother
\usepackage[rigidchapters,nobottomtitles*,pageatnewline]{titlesec}
\titlespacing*{\section}
{0em}
{2em}
{0.5em}
\titlespacing*{\subsection}
{0em}
{2em}
{0.5em}
\titleformat{\section}
[display]
{\fontencoding{T1}\fontfamily{phv}\fontsize{11pt}{13.2pt}\selectfont}
{\thesection}
{1ex}
{}
{}
\titleformat{\subsection}
[display]
{\fontencoding{T1}\fontfamily{phv}\fontsize{11pt}{13.2pt}\selectfont}
{\thesubsection}
{0em}
{}
{}
%
\usepackage{titletoc}
\titlecontents{chapter}
[0em]
{\bfseries}
{Chapter \thecontentslabel\\*\hspace*{.7em}}
{}
{\hfill\contentspage}
\titlecontents{section}
[1.5em]
{}
{{\sffamily\thecontentslabel}\\*\hspace*{.7em}}
{}
{\titlerule*[.5pc]{.}\contentspage}
\titlecontents*{subsection}
[3.8em]
{}
{{\sffamily\thecontentslabel}\\*\hspace*{.7em}}
{}
{\titlerule*[.5pc]{.}\contentspage}
%
\begin{document}
\chapter{Foo}
\lipsum[1]
\section{Bar}
\lipsum[2]
\subsection{Qux}
\lipsum[3]
\section{Quux}
\lipsum[4]
\subsection{Quux1}
\lipsum[5]
\chapter{foo}
\section{bar}
\lipsum[4]
\subsection{qux}
\lipsum[5]
\tableofcontents
\end{document}
Remove the tocfullflat
option from the package tocstyle
.
% arara: pdflatex
% arara: pdflatex
\documentclass[12pt, a4paper]{report}
\usepackage{geometry}
\geometry{verbose,tmargin=25mm,bmargin=25mm,lmargin=30mm,rmargin=25mm}
\setlength{\parskip}{\medskipamount}
\usepackage{tocloft}
\usepackage{times}
\renewcommand{\baselinestretch}{1.5}
%\renewcommand{\cftaftertoctitle}{\hfill} % if you want this title centred, this has to go away
\usepackage{minitoc}
\usepackage{tocstyle} % removed the flat toc option here
\usepackage{titlesec}
\titleformat{\chapter}[block]
{\normalfont\fontsize{14pt}{12pt}\selectfont\bfseries
\centering} {\MakeUppercase \thechapter.}{1pt}{\MakeUppercase}
\titleformat{\section}
{\normalfont\fontsize{12pt}{14pt}\selectfont\bfseries}{\thesection .}{1pt}{}
\titleformat{\subsection}
{\normalfont\fontsize{12pt}{14pt}\selectfont\bfseries}{\thesubsection .}{1pt}{}
%\titleformat{\subsubsection}
%{\normalfont\fontsize{12pt}{14pt}\selectfont\bfseries}{\thesubsubsection .}{1pt}{} % not used here
\titlespacing*{\chapter} {0pt}{12pt}{0.3ex plus .2ex}
\titlespacing*{\section} {0pt}{12pt}{0.3ex plus .2ex}
\titlespacing*{\subsection}{0pt}{12pt}{0.3ex plus .2ex}
%\titlespacing*{\subsubsection}{0pt}{12pt}{0.3ex plus .2ex} % not used here
\begin{document}
\renewcommand{\cfttoctitlefont}{\large\hfil\textbf}
\pagenumbering{roman} \setcounter{page}{5}
\def\contentsname{CONTENTS}
\setlength{\cftsecindent}{0em}
\setlength{\cftsubsecindent}{25em}
\tableofcontents
\clearpage
\pagenumbering{arabic} \setcounter{page}{1}
\addcontentsline{toc}{chapter}{Contents}
\chapter{A}
\section{Introduction}
\subsection{a}
\end{document}
Best Answer
Use
\addtocontents
instead of\addcontentsline
. The former is generic, the latter is used only to add "normal" entries.