Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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:

Table of Contents result

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

share|improve this question
    
Welcome to TeX.SX! A tip: If you indent lines by 4 spaces, they'll be marked as a code sample. You can also highlight the code and click the "code" button (with "{}" on it). –  Adam Liter Apr 12 at 4:24
    
Could you provide us with a minimal working example (MWE) so we have something to work with? Since this document seems like it will be very comprehensive (a thesis), be sure to give all details you require in terms of ToC-related packages. –  Werner Apr 12 at 5:32
add comment

2 Answers 2

up vote 4 down vote accepted

You are not using \addcontentsline in the correct way.

Instead of

\addcontentsline{toc}{chapter}{\numberline{}Abstract}

you have to use

\addcontentsline{toc}{chapter}{Abstract}

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:

\titlecontents{chapter}% <section-type>
  [0pt]% <left>
  {\bfseries}% <above-code>
  {\chaptername\ \thecontentslabel:\quad}% <numbered-entry-format>
  {}% <numberless-entry-format>
  {\hfill\contentspage}% <filler-page-format>

MWE:

\documentclass[12pt]{report}
\usepackage[utf8]{inputenc}

\usepackage{titletoc}%
\titlecontents{chapter}% <section-type>
  [0pt]% <left>
  {\bfseries}% <above-code>
  {\chaptername\ \thecontentslabel:\quad}% <numbered-entry-format>
  {}% <numberless-entry-format>
  {\hfill\contentspage}% <filler-page-format>

\usepackage{lipsum}

\usepackage{setspace}

\begin{document}

\pagenumbering{roman}
\clearpage
\setcounter{page}{2}

\chapter*{Abstract}
\addcontentsline{toc}{chapter}{Abstract}
\lipsum[1]

\chapter*{Acknowledgements}
\addcontentsline{toc}{chapter}{Acknowledgements}
\lipsum[1]

\begin{doublespace}
\renewcommand*{\contentsname}{Table of Contents}
\tableofcontents
\addcontentsline{toc}{chapter}{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} 

enter image description here

In regards of the Overfull \hbox warnings, I don't know a good way to solve it with titletoc, but I know a better way with tocloft, which works much better than titletoc.

So, you can replace the titletoc stuff

\usepackage{titletoc}%
\titlecontents{chapter}% <section-type>
  [0pt]% <left>
  {\bfseries}% <above-code>
  {\chaptername\ \thecontentslabel:\quad}% <numbered-entry-format>
  {}% <numberless-entry-format>
  {\hfill\contentspage}% <filler-page-format>

with

\usepackage[titles]{tocloft}
\newlength\mylength
\renewcommand\cftchappresnum{\chaptername~}
\renewcommand\cftchapaftersnum{:}
\settowidth\mylength{\cftchappresnum\cftchapaftersnum\quad}
\addtolength\cftchapnumwidth{\mylength}

and the following MWE

\documentclass[12pt]{report}
\usepackage[utf8]{inputenc}

\usepackage[titles]{tocloft}
\newlength\mylength
\renewcommand\cftchappresnum{\chaptername~}
\renewcommand\cftchapaftersnum{:}
\settowidth\mylength{\cftchappresnum\cftchapaftersnum\quad}
\addtolength\cftchapnumwidth{\mylength}

\usepackage{lipsum}

\usepackage{setspace}

\begin{document}

\pagenumbering{roman}
\clearpage
\setcounter{page}{2}

\chapter*{Abstract}
\addcontentsline{toc}{chapter}{Abstract}
\lipsum[1]

\chapter*{Acknowledgements}
\addcontentsline{toc}{chapter}{Acknowledgements}
\lipsum[1]

\begin{doublespace}
\renewcommand*{\contentsname}{Table of Contents}
\tableofcontents
\addcontentsline{toc}{chapter}{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} 

will give you the following result

enter image description here

share|improve this answer
add comment

The following works for me (based on your MWE), but it's a bit of a hack though.

\usepackage{titletoc}% 
\titlecontents{chapter}% <section-type>
  [0pt]% <left>
  {}% <above-code>
  {\bfseries\chaptername\ \thecontentslabel:\quad}% <numbered-entry-format>
  {\bfseries\raggedright\hspace{-0.575\linewidth}}% <numberless-entry-format>
  {\bfseries\hfill\contentspage}% <filler-page-format>

The hbox warnings look like they are caused by the page numbers being boldface for chapters (but not sections). Do you want it that way, or do you want all page numbers in the same (non-bold) font?

share|improve this answer
    
Welcome to TeX.SX! Nice answer, I cannot help but feel though that your last question would be better suited in a comment to the question. –  moewe Apr 12 at 8:18
    
Sure, but I don't have enough rep to do that. You can repost it there if you want. –  semi-extrinsic Apr 12 at 9:00
    
Ahh, sorry I tend to forget these things. –  moewe Apr 12 at 9:25
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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