0

I want to add "Chapter " before each of my sections on the table of contents. I'm using \titlecontents as in the following code:

\documentclass[a4paper,12pt]{article}
\usepackage{amsmath,titletoc}

\titlecontents*{section}[0pt]{}
{\\ \bfseries\text{Chapter } \thecontentslabel\quad}{}{\bf\hfill\contentspage}

\begin{document}
\tableofcontents

\section{First Chapter}
\section{Second Chapter}
\subsection{First subsection}
\section{Third Chapter}
\subsection{Second subsection}
\subsubsection{First subsubsection}

\end{document}

which produces:

enter image description here

This is almost perfect but it has the undesired result that the page number for the first chapter (\section) is not inline with the other page numbers and there is no extra line space after chapter 1.

Strangely, I have found that this is not the case if my first chapter (\section) has a subsection, as in the following picture: enter image description here

Unfortunately I do not want all of my chapters (\section 's) to have subsections, so are there any modifications I can make to my code to fix the errors shown in the first picture? Thank you very much

P.S. while there are already a few questions about adding words before section titles in the ToC, I believe my problem is original in that I cannot accept any of the usual answers. Namely, I must continue to use the {article} document class and so cannot use \chapter{}, sorry, I'm being awkward!

2

Don't use \\:

\documentclass[a4paper,12pt]{article}
\usepackage{amsmath,titletoc}

\titlecontents{section}[0pt]
{}
{\bfseries\text{Chapter } \thecontentslabel\quad}
{}
{\hfill\bfseries\contentspage}

\usepackage{lipsum}
\begin{document}
\tableofcontents

\section{First Chapter}
\lipsum[1]
\section{Second Chapter}
\subsection{First subsection}
\section{Third Chapter}
\subsection{Second subsection}
\subsubsection{First subsubsection}

\end{document}

enter image description here

1
  • Thanks, I'm embarrassed it was as simple as that... also, removing the asterisk * has made it better. – analytic Nov 25 '17 at 17:11

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.