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 am using the tocloft package already. I have a couple of long chapter names that wrap onto a second line, but it lines it up with the section numbers below. I must have this new line line up with the original chapter name. I have seen one other similar question, but it was not answered. Example:

CHAPTER 1:  THIS IS AN EXTREMELY LONG,
    LONG CHAPTER NAME.......................2
    1.1 blah blah...........................3
    1.2 blah blah...........................4

I need it to be:

CHAPTER 1:  THIS IS AN EXTREMELY LONG,
            LONG CHAPTER NAME...............2
    1.1 blah blah...........................3
    1.2 blah blah...........................4

Hope someone can help!

Thanks in advance!

Note: Someone else wrote the class file that I am using for my dissertation, so I am trying to edit it to fit the formatting needs of my University.

Here is the original code that's being used to generate the TOC:

  % TABLE OF CONTENTS ----------------------------------------------------------
\renewcommand{\cftbeforechapskip}{\baselineskip}        % allow spacing after each chapter/section entry
\renewcommand{\contentsname}{TABLE OF CONTENTS}
\renewcommand{\cftbeforetoctitleskip}{-0.25in}        % Title is 1in from top
\renewcommand{\cftaftertoctitleskip}{2.0\baselineskip}% 1 double space after title
\renewcommand{\cfttoctitlefont}{\hfill}               % Blank space before title
\renewcommand{\cftaftertoctitle}{\hfill}              % Blank space after title
\renewcommand{\cftchapfont}{ }                        % Can make it bold faced here
\renewcommand{\cftchapleader}{\cftdotfill{\cftchapdotsep}}
\renewcommand{\cftchapdotsep}{\cftdotsep}             % Puts dots after chapter entries
\renewcommand{\cftchappresnum}{CHAPTER }                %
\renewcommand{\cftchapaftersnum}{ }                     %
\renewcommand{\cftchapaftersnumb}{\phantom{CHAPTER}\rm} %
\renewcommand{\cftsecleader}{\cftdotfill{\cftsecdotsep}}%
\renewcommand{\cftchappagefont}{ }                      %

This compiles fine, no errors... When I replace the line

\renewcommand{\cftchappresnum}{CHAPTER }                %
with
\renewcommand{\cftchappresnum}{CHAPTER\ }               %

as advised, and add the line

\renewcommand{\cftchapnumwidth}{1in}

I get 9 errors in the .toc file.

Update: Repaired the 9 errors in .toc file by using

\setlength{\cftchapnumwidth}{1.2in}

instead of

\renewcommand{\cftchapnumwidth}{1in}.

The last thing I'm working on is how these fixes will jive with the appendix patch:

\newcommand*\tocappendixpatch{%
  \addtocontents{toc}{\setcounter{tocdepth}{0}}
  \addtocontents{toc}{\protect\renewcommand*\protect\cftchappresnum{\@chapapp\ }}
  \addtocontents{toc}{\settowidth{\cftchapnumwidth}{\hspace*{9mm}}}
  \renewcommand{\thesection}%
    {\Alph{chapter}.\arabic{section}\hspace{-.5em}\setcounter{equation}{0}}
}

The rest of the TOC looks excellent, but I think the code in the appendixpatch is conflicting, so I'm working on figuring that out, now.

Update: I got it! I replaced the line

\addtocontents{toc}{\settowidth{\cftchapnumwidth}{\hspace*{9mm}}}

with

\setlength{\cftchapnumwidth}{1.2in}

within the appendix patch, and the spacing came out perfectly, matching the lines above it.
This has been quite stressful. It took my whole weekend! It would've been much simpler to just shorten the chapter names!!

Thanks to all of you who helped!! I hope I can help people with their questions later when I have time!

share|improve this question
    
You can also give abbreviated chapter names as an optional argument: \chapter[Short Name]{Long Name} The short name is then used in the TOC –  Lagerbaer Apr 18 '11 at 0:08
add comment

1 Answer

up vote 10 down vote accepted

There are numerous problems with the code you posted, which will explain why the titles don't line up.

Specifically:

\renewcommand{\cftchapfont}{ } % this should not have a space

it should be

\renewcommand{\cftchapfont}{} % notice there is no space here

The following command:

\renewcommand{\cftchapaftersnumb}{\phantom{CHAPTER}\rm} 

is a hack for spacing. It should be removed altogether.

Another extra space in:

\renewcommand{\cftchappagefont}{ }    % this should not have a space either

should be

\renewcommand{\cftchappagefont}{}

You can specify the width of the chapter number and the text will wrap appropriately. So adding your commands to a minimal document, you get the following:

\documentclass{book}
\usepackage{tocloft}

\begin{document}
\renewcommand{\cftbeforechapskip}{\baselineskip}      % allow spacing after each chapter/section entry
\renewcommand{\contentsname}{TABLE OF CONTENTS}
\renewcommand{\cftbeforetoctitleskip}{-0.25in}        % Title is 1in from top
\renewcommand{\cftaftertoctitleskip}{2.0\baselineskip}% 1 double space after title
\renewcommand{\cfttoctitlefont}{\hfill}               % Blank space before title
\renewcommand{\cftaftertoctitle}{\hfill}              % Blank space after title
\renewcommand{\cftchapfont}{}                         % Can make it bold faced here; don't put a space in the {}
\renewcommand{\cftchapleader}{\cftdotfill{\cftchapdotsep}}
\renewcommand{\cftchapdotsep}{\cftdotsep}             % Puts dots after chapter entries
\renewcommand{\cftchappresnum}{CHAPTER\ }             %
\renewcommand{\cftchapaftersnum}{}                    % Don't put a space in the {}
\renewcommand{\cftsecleader}{\cftdotfill{\cftsecdotsep}}%
\renewcommand{\cftchappagefont}{}                      %
\renewcommand{\cftchapnumwidth}{1in}
\frontmatter
\tableofcontents

\mainmatter
\chapter{A really long chapter heading that will wrap around in the table of contents}
\section{First section}
\section{Second section}
\chapter{Another chapter}
\section{Another section}
\end{document}

output of code

share|improve this answer
    
Thank you, but this doesn't seem to be working with my code. I see that the following workaround (which I read has to do with hypertext and tocloft being used at the same time), which prevents the first line from being boldface: \renewcommand{\cftchapaftersnum}{ } % \renewcommand{\cftchapaftersnumb}{\phantom{CHAPTER}\rm} % \renewcommand{\cftsecleader}{\cftdotfill{\cftsecdotsep}}% \renewcommand{\cftchappagefont}{ } % Also, the wrapped around text is ALMOST lining up, but is not as perfect as your sample shows. Compiling now gives 9 errors in .toc file –  Valjean Elander Apr 18 '11 at 0:27
    
So add an example just like mine (but adapted to what you have done) to your question, so that we can see what you are doing. –  Alan Munn Apr 18 '11 at 0:30
    
Ok, I edited my main question to include the code and more details. I will include a picture shortly. I am new at this message board, so I appreciate your patience. –  Valjean Elander Apr 18 '11 at 0:59
    
It won't let me submit a picture to show the output since I am a new user. –  Valjean Elander Apr 18 '11 at 1:03
2  
@Valjean Elander: instead of using \renewcommand{\cftchapfont}{ } (which adds an undesired space) use \renewcommand{\cftchapfont}{\normalfont}. –  Gonzalo Medina Apr 18 '11 at 2:11
show 10 more comments

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.