2

Basically, here's my MWE, and I need to include "Chapter" before every section title in the ToC (without changing anything else).

   \documentclass[12pt]{article}
\usepackage[utf8]{inputenc} 
\usepackage[english]{babel}
\usepackage[titles]{tocloft}
\usepackage{titlesec}
\usepackage{titletoc}

\addto\captionsenglish{ \renewcommand*\contentsname{\centerline{TABLE OF CONTENTS}}}

%\renewcommand{\thesection}{CHAPTER}
%\renewcommand{\cftsecpresnum}{Chapter \thesection}
\titleformat{\section}[display]%
{\null\vskip1em\sffamily\bfseries\filcenter}{Chapter \thesection}{0em}{}[]
\titlespacing*{\section}{0em}{1em}{1em}

\titlecontents{section}
[1.5em] % ie, 1.5em (chapter) + 2.3em
{}
{\contentslabel{1em}}
{\hspace*{-1.5em}}
{\titlerule*[0.5pc]{.}\contentspage}

\begin{document}
\newpage
\tableofcontents
\newpage

\section{Section One}
\section{Section Two}
Content
\end{document}

The commented out code is what I've already tried. The first one just changes the number to "CHAPTER" and doesn't move the text in the ToC (so it just overlays on top of the name of the section), and if I include "\thesection" after "CHAPTER" it creates an infinite loop definition error. The second one causes no differences, and the code still compiles.

Thanks!

2
  • 1
    You may have noticed that articles don't have chapters by design, but reports and books have them.
    – Johannes_B
    Nov 21, 2015 at 11:04
  • Yep! But my thesis requires that it says "Chapter".
    – Conor
    Nov 22, 2015 at 3:53

2 Answers 2

3

Here is a solution. I didn't load tocloft, since I use titletoc. Also I added a formatting for thoe unnumbered sections which should appear in the table of contents:

 \documentclass[12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage[showframe]{geometry}
\usepackage{titlesec}
\usepackage{titletoc}

\addto\captionsenglish{ \renewcommand*\contentsname{\centerline{TABLE OF CONTENTS}}}

\titleformat{\section}[display]%
{\null\vskip1em\sffamily\bfseries\filcenter}{Chapter \thesection}{0em}{}[]
\titleformat{name = \section, numberless}[block]%
{\null\vskip1em\sffamily\bfseries\filcenter}{}{0em}{}
\titlespacing*{\section}{0em}{1em}{1em}

\titlecontents{section}
[7em] % ie, width of contentslabel + 0.5em
{\medskip}
{\contentslabel[\MakeUppercase\chaptername~\thecontentslabel]{6.5em}}%\thecontentslabel
{\hspace*{-6.5em}}
{\titlerule*[0.5pc]{.}\contentspage}

\begin{document}

\tableofcontents
\newpage

\section*{An Unnumbered Section}
\addcontentsline{toc}{section}{An Unnumbered Section}
\section{Section One}
\subsection{A first subsection}
\section{Section Two}
Content

\end{document} 

enter image description here

7
  • This should work, I'll be able to check tomorrow and let you know, thank you!
    – Conor
    Nov 22, 2015 at 3:54
  • Sorry, I just got to this (holiday travel, etc). This is ALMOST perfect (I definitely didn't even think about unnumbered sections at first, so thank you!), I just realized I didn't frame the question right. I do actually need the number after "Chapter" for the numbered sections (IE, CHAPTER 1 Section One). I'm guessing that has something to do with the "numberless", but I've tried a few modifications and it either doesn't change anything or causes an error in the code.
    – Conor
    Nov 25, 2015 at 5:28
  • Whoops just realized numberless is the formatting for the numbered sections. So I'm not sure what to change to add numbers in front of the chapters.
    – Conor
    Nov 29, 2015 at 23:47
  • I'm sorry, I mingled the section number and the numlmber in the sections title. I fixed that. Is it OK now?
    – Bernard
    Nov 30, 2015 at 0:37
  • That worked, thanks! I've marked your previous answer as correct.
    – Conor
    Nov 30, 2015 at 1:06
0

I am editing a book using tstextbook, which includes use of package titletoc.

Solutions given in this thread did not helped me. Because of package titlesec introduce too many error in my compilation, resulting in a bigger problems that that I was trying to solve. The same case when I tried to test solutions that use package tocloft.

After some hours researching and testing, my solution is simple: just by modifying the of the \titlecontents command for "chapter".

My original entry:

{\color{tssteelblue}\contentslabel[\Large\thecontentslabel]{1.25cm}} %ORIGINAL

A working solution:

{\chaptername\ \thecontentslabel:\quad}% <numbered-entry-format> %It compiled within my code without errors!!!

My final solution, that solved my requirement:

{\color{tssteelblue}\Large\chaptername\ \thecontentslabel.\space} %Final solution

*Please consider that my book is in Spanish.

My final complete code for chapter:

%\titlecontents{ <section> }[ <left> ]
%{ <above-code> }
%{ <numbered-entry-format> }{ <numberless-entry-format> }
%{ <filler-page-format> }[ <below-code> ]

\titlecontents{chapter}[0cm]
{\addvspace{14pt}\large\sffamily\bfseries}
{\color{tssteelblue}\Large\chaptername\ \thecontentslabel.\space} %Final solution
{}
{\color{tssteelblue}\normalsize\sffamily\bfseries\;\titlerule*[.5pc]{.}\;\thecontentspage}

TOC fragments: before and after the solution

My solution given from here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .