1

I have:

\documentclass[12pt]{book}

\begin{document}
\tableofcontents

\chapter{chapter name}
\section{section name}
\subsection{subsection name}
\end{document}

I get enter image description here

I want to add the word 'Chapter' before the number 1 where it is written chapter name. I want also to add a point line in front of the chapter name like in the section line.

I try to use this:

\documentclass[12pt]{book}

\usepackage[utf8]{inputenc}
\usepackage{newtxtext}
\usepackage[english]{babel}
\usepackage{titletoc}

\addto\captionsenglish{\renewcommand*\contentsname{Contents}}

\titlecontents{chapter}[5.3em]
{\vspace{0.3cm}}
{\contentslabel[\textbf{\chaptername~\thecontentslabel}]{5.3em}}
{\hspace*{-5.3em}}
{\titlerule{1pc}{.}\contentspage}[\smallskip]

\titlecontents{section}[5.3em]
{\smallskip}
{\thecontentslabel\enspace}
{\hspace*{-5.3em}}
{\hfill\contentspage}

\titlecontents{subsection}[6.92em]
{\smallskip}
{\thecontentslabel\enspace}
{\hspace*{-6.92em}}
{\hfill\contentspage}

    \begin{document}

    \tableofcontents
    \newpage

    \chapter*{Preface}
    \addcontentsline{toc}{chapter}{Preface}
    \chapter{Looking-Glass House}
\section{A First section}
\section{Another section}
\subsection{A subsection}
    \end{document}

But I have this: enter image description here

I have problem with the dotted line and I want that tha chapter nae be bold !

S_25
  • 159
  • I think we have a lot of questions on this here, please have a look first –  Jun 24 '17 at 13:37
  • 2
    See https://tex.stackexchange.com/questions/278804/add-chapter-word-into-toc-using-tocbibind-package?s=2|1.2481 – John Kormylo Jun 24 '17 at 13:39

1 Answers1

1

Here is how to do it with titletoc. Note you'll have to redo the formatting of lower level sectioning titles (mainly the horizontal spacing) to make the layout consistent. The lengths may have to be adjusted depending on the document font, the font size, &c.

    \documentclass[12pt]{book}
    \usepackage[utf8]{inputenc}
    \usepackage{fourier, erewhon, cabin}
    %\usepackage{newtxtext}
    \usepackage[english]{babel}
    \usepackage[showframe]{geometry}
    \usepackage{titletoc}
    \usepackage{lipsum} \addto\captionsenglish{ \renewcommand*\contentsname{\centerline{Table of contents}}}

    \titlecontents{chapter}
    [5.5em] %5.3
    {\bigskip}
    {\contentslabel[\bfseries\textsc{\chaptername}~\thecontentslabel]{5.5em}\textbf}%\thecontentslabel
    {\hspace*{-5.5em}\textbf}% unnumbered chapters
    {\titlerule*[1pc]{.}\contentspage}[\smallskip]%
%
 \titlecontents{section}
 [5.5em] % i
 {\smallskip}
 {\thecontentslabel\enspace}%\thecontentslabel
 {\hspace*{-5.5em}}
 {\titlerule*[1pc]{.}\contentspage}%]

 \titlecontents{subsection}
 [7.12em] %
 {\smallskip}
 {\thecontentslabel\enspace}%\thecontentslabel
 {\hspace*{7.12em}}
 {\titlerule*[1pc]{.}\contentspage}

    \begin{document}

    \tableofcontents
    \newpage

    \chapter*{Preface}
    \addcontentsline{toc}{chapter}{Preface}
    \chapter{Looking-Glass House}
\section{A First section}
\section{Another section}
\subsection{A subsection}
    \lipsum[1]
    \chapter{The Garden of Live Flowers}
    \lipsum[2-5]
    \chapter{Looking-Glass Insects}
    \lipsum[6]
    \chapter{Tweedledum and Tweedledee}

    \end{document} 

enter image description here

Bernard
  • 271,350
  • How can I delete page framing? – S_25 Jun 24 '17 at 19:28
  • Remove the [showframe] option of geometry. It was there only to check the alignment at the left margin. – Bernard Jun 24 '17 at 19:37
  • okay. Is it possible to add the points in the rest of the line and to put the font of the contents like the font of the book (Times) ? – S_25 Jun 24 '17 at 19:56
  • I want to remove also the subsections please. Thank you very much – S_25 Jun 24 '17 at 19:57
  • Do you mean adding the dotted line for chapters? As for the font, it's only because I started from an old template. Replace \usepackage{fourier, erewhon,cabin} with\usepackage{times}. However, notetimesis obsolete, as it doesn't change the maths fonts. Unless you have absolutely no maths to write, it's better to loadnewtxtextandnewtxmath, based onTeX Gyre Termes`, a Times-clone. – Bernard Jun 24 '17 at 20:09
  • Concerning the subsections, you have to remove \titlecontents{subsection}{…} (which gets useless) and add in the preamble \setcounter{tocdepth}{1}. – Bernard Jun 24 '17 at 20:10
  • Yes I want to add the dotted line for chapters, sections and subsections ? – S_25 Jun 24 '17 at 20:13
  • I've edited my answer to explain that: replace \hfill with \titlerule{1pc}{.}. 1pc (1 pica) is the distance between consecutive dots. You can change this value. – Bernard Jun 24 '17 at 20:39
  • I've edited my question. As you can see I have a problem in the dotted line. I want also that the chapter name be bold. – S_25 Jun 24 '17 at 21:12
  • Only the word ‘Chapter’ or the chapter title too? – Bernard Jun 24 '17 at 21:37
  • Both in bold: the word 'chapter' and the chapter title. How can I modify the problem of the dooted line please ? – S_25 Jun 25 '17 at 11:14