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!

  • 1
    You may have noticed that articles don't have chapters by design, but reports and books have them. – Johannes_B Nov 21 '15 at 11:04
  • Yep! But my thesis requires that it says "Chapter". – Conor Nov 22 '15 at 3:53
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

|improve this answer|||||
  • This should work, I'll be able to check tomorrow and let you know, thank you! – Conor Nov 22 '15 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 '15 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 '15 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 '15 at 0:37
  • That worked, thanks! I've marked your previous answer as correct. – Conor Nov 30 '15 at 1:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for?Browse other questions tagged or ask your own question.