I'm trying to use the titletoc
package to add the word "Chapter" only to my numbered entries in my Table of Contents. I'm using a report
document class. I'm really close (I think), I just need to know how to align the numberless entries with the word "Chapter" from the numbered entries.
Here's what I've got:
\usepackage{titletoc}%
\titlecontents{chapter}% <section-type>
[0pt]% <left>
{}% <above-code>
{\bfseries\chaptername\ \thecontentslabel\quad}% <numbered-entry-format>
{\bfseries}% <numberless-entry-format>
{\bfseries\hfill\contentspage}% <filler-page-format>
Which gives me:
I'd like to align those numberless chapters on the left hand side with the word "Chapter". Also, I'm receiving \hbox
warnings for the page numbers with four or more characters (such as viii) and am not sure what to do about those. I'm new to LaTeX and am at a loss. I tried looking through the titletoc
documentation but was unsuccessful. Thanks in advance!
EDIT: As requested, here is a MWE:
\documentclass[12pt]{report}
\usepackage[utf8]{inputenc}
\usepackage{titletoc}%
\titlecontents{chapter}% <section-type>
[0pt]% <left>
{}% <above-code>
{\bfseries\chaptername\ \thecontentslabel:\quad}% <numbered-entry-format>
{\bfseries}% <numberless-entry-format>
{\bfseries\hfill\contentspage}% <filler-page-format>
\usepackage{lipsum}
\usepackage{setspace}
\begin{document}
\pagenumbering{roman}
\clearpage
\setcounter{page}{2}
\chapter*{Abstract}
\addcontentsline{toc}{chapter}{\numberline{}Abstract}
\lipsum[1]
\chapter*{Acknowledgements}
\addcontentsline{toc}{chapter}{\numberline{}Acknowledgements}
\lipsum[1]
\begin{doublespace}
\renewcommand*{\contentsname}{Table of Contents}
\tableofcontents
\addcontentsline{toc}{chapter}{\numberline{}Table of Contents}
\end{doublespace}
\pagenumbering{arabic}
%\setcounter{page}{255} % % Uncomment to see \hbox warnings due to long TOC page number
\chapter{Introduction}
\lipsum[1]
\section{Section one}
\lipsum[1]
\chapter{Second Chapter}
\lipsum[1]
\section{Another section}
\lipsum[1]
\end{document}
Note: remove the comment to receive the \hbox
warnings. Thanks again
Best Answer
You are not using
\addcontentsline
in the correct way.Instead of
you have to use
and the result will be good.
Also notice that
\bfseries
can be specified in the first mandatory argument, so not to be repeated in the others:MWE:
In regards of the Overfull
\hbox
warnings, I don't know a good way to solve it withtitletoc
, but I know a better way withtocloft
, which works much better thantitletoc
.So, you can replace the
titletoc
stuffwith
and the following MWE
will give you the following result